prod-server.js 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. const express = require('express')
  2. const app = express()
  3. // const proxy = require('http-proxy-middleware')
  4. const host = process.env.HOST || '0.0.0.0'
  5. const port = process.env.PORT || 36500
  6. process.noDeprecation = true
  7. app.set('port', port)
  8. app.use(express.static('dist'))
  9. // 只有内部路由跳转至页面
  10. const routerTable = ['/', '/center/*', '/factoring', '/planDetail', '/withdrawDetail', '/result']
  11. routerTable.forEach(router => {
  12. app.get(router, (req, res, next) => {
  13. res.sendfile('dist/index.html')
  14. })
  15. })
  16. // http proxy
  17. // let proxyConfig = require('../config/proxy')
  18. // const env = require('../config/env')
  19. // 请求代理,dev模式下使用,接口服务器如果支持跨域可去掉
  20. // const proxyTable = proxyConfig.proxyTable
  21. // if (proxyTable) {
  22. // // 本地代理支持localhost、127.0.0.1等不同地址跨域
  23. // app.use((req, res, next) => {
  24. // res.header('Access-Control-Allow-Origin', '*')
  25. // res.header('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE')
  26. // res.header('Access-Control-Allow-Headers', 'Content-Type')
  27. // res.header('Access-Control-Allow-Credentials', 'true')
  28. // // const refer = res.req.headers.referer
  29. // // if (refer && url.parse(refer, true).query.type === 'erp') {
  30. // // res.cookie('type', 'erp')
  31. // // }
  32. // next()
  33. // })
  34. // const defaultOptions = {
  35. // // target: env.baseUrl
  36. // }
  37. // Object.keys(proxyTable).forEach((context) => {
  38. // var options = proxyTable[context]
  39. // if (typeof options === 'string') {
  40. // options = { target: options }
  41. // }
  42. // app.use(proxy(context, Object.assign(defaultOptions, options)))
  43. // })
  44. // }
  45. app.listen(port, host)
  46. console.log(`finance-web Server listening on ${host} : ${port}, at ${new Date().toLocaleString()}`)