const express = require('express') const app = express() // const proxy = require('http-proxy-middleware') const host = process.env.HOST || '0.0.0.0' const port = process.env.PORT || 36500 process.noDeprecation = true app.set('port', port) app.use(express.static('dist')) // 只有内部路由跳转至页面 const routerTable = ['/', '/center/*', '/factoring', '/planDetail', '/withdrawDetail', '/result'] routerTable.forEach(router => { app.get(router, (req, res, next) => { res.sendfile('dist/index.html') }) }) // http proxy // let proxyConfig = require('../config/proxy') // const env = require('../config/env') // 请求代理,dev模式下使用,接口服务器如果支持跨域可去掉 // const proxyTable = proxyConfig.proxyTable // if (proxyTable) { // // 本地代理支持localhost、127.0.0.1等不同地址跨域 // app.use((req, res, next) => { // res.header('Access-Control-Allow-Origin', '*') // res.header('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE') // res.header('Access-Control-Allow-Headers', 'Content-Type') // res.header('Access-Control-Allow-Credentials', 'true') // // const refer = res.req.headers.referer // // if (refer && url.parse(refer, true).query.type === 'erp') { // // res.cookie('type', 'erp') // // } // next() // }) // const defaultOptions = { // // target: env.baseUrl // } // Object.keys(proxyTable).forEach((context) => { // var options = proxyTable[context] // if (typeof options === 'string') { // options = { target: options } // } // app.use(proxy(context, Object.assign(defaultOptions, options))) // }) // } app.listen(port, host) console.log(`finance-web Server listening on ${host} : ${port}, at ${new Date().toLocaleString()}`)