server.ts 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. import app from "./app"
  2. import * as open from "open"
  3. import config from "./config"
  4. import { user } from "./models/mysql"
  5. import Logger from "./loaders/logger"
  6. import { queryTable } from "./utils/initMysql"
  7. const expressSwagger = require("express-swagger-generator")(app)
  8. expressSwagger(config.options)
  9. queryTable(user)
  10. import {
  11. login,
  12. register,
  13. updateList,
  14. deleteList,
  15. searchPage,
  16. searchVague,
  17. captcha,
  18. } from "./router/api/mysql"
  19. app.post('/login', (req, res) => {
  20. login(req, res)
  21. })
  22. app.post('/register', (req, res) => {
  23. register(req, res)
  24. })
  25. app.get('/updateList', (req, res) => {
  26. updateList(req, res)
  27. })
  28. app.get('/deleteList', (req, res) => {
  29. deleteList(req, res)
  30. })
  31. app.post('/searchPage', (req, res) => {
  32. searchPage(req, res)
  33. })
  34. app.post('/searchVague', (req, res) => {
  35. searchVague(req, res)
  36. })
  37. app.get('/captcha', (req, res) => {
  38. captcha(req, res)
  39. })
  40. app.listen(config.port, () => {
  41. Logger.info(`
  42. ################################################
  43. 🛡️ Swagger文档地址: http://localhost:${config.port} 🛡️
  44. ################################################
  45. `)
  46. }).on('error', err => {
  47. Logger.error(err)
  48. process.exit(1)
  49. })
  50. // open(`http://localhost:${config.port}`) // 自动打开默认浏览器