- const express = require('express')
- const history = require('connect-history-api-fallback')
- const { createProxyMiddleware } = require('http-proxy-middleware')
-
- let app = express()
-
- app.use(history())
-
- // //匹配api开头的请求,实际转发的请求保api这三个字母
- // app.use(
- // '/api',
- // createProxyMiddleware({
- // target: 'http://localhost:85',
- // changeOrigin: true,
- // })
- // )
-
- app.use(
- '/master',
- createProxyMiddleware({
- target: 'http://xxx:8080',
- secure: false,
- changeOrigin: true,
- pathRewrite: function (path, req) {
- // 可以在这里重写路径
- return `/master${path}`
- },
- on: {
- proxyReq: (proxyReq, req, res) => {
- //console.log(proxyReq)
- /* handle proxyReq */
- },
- proxyRes: (proxyRes, req, res) => {
- //console.log(proxyRes)
- /* handle proxyRes */
- },
- error: (err, req, res) => {
- console.log(err)
- /* handle error */
- },
- },
- })
- )
-
- app.use(express.static('./dist'))
-
- app.listen(99, () => {
- console.log('http://localhost:99')
- console.log('success')
- })
人工智能学习网站