server.ts 1007 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. import app from "./app";
  2. const PORT = 3000;
  3. const expressSwagger = require('express-swagger-generator')(app)
  4. // 引入测试数据
  5. const test = require("./router/api/test")
  6. let options = {
  7. swaggerDefinition: {
  8. info: {
  9. description: 'This is a sample server',
  10. title: 'Swagger',
  11. version: '1.0.0'
  12. },
  13. host: 'localhost:3000',
  14. basePath: '/',
  15. produces: ['application/json', 'application/xml'],
  16. schemes: ['http', 'https'],
  17. securityDefinitions: {
  18. JWT: {
  19. type: 'apiKey',
  20. in: 'header',
  21. name: 'Authorization',
  22. description: ''
  23. }
  24. }
  25. },
  26. route: {
  27. url: '/swagger-ui.html',
  28. docs: '/swagger.json' //swagger文件 api
  29. },
  30. basedir: __dirname, //app absolute path
  31. files: ['./router/api/*.ts'] //Path to the API handle folder
  32. }
  33. expressSwagger(options)
  34. app.get('/getApi', (req, res) => {
  35. test.testGetApi(req, res)
  36. })
  37. app.listen(PORT, () => {
  38. console.log('Swagger文档地址:', `http://localhost:${PORT}`);
  39. })