增加开发模式代理

master
落雨楓 2 years ago
parent e280117be6
commit 0b96c79ccd

@ -0,0 +1,60 @@
// server.js
const express = require('express')
const next = require('next')
const { createProxyMiddleware } = require('http-proxy-middleware');
const devProxy = {
'/generate-stream': {
target: 'http://localhost:6969',
changeOrigin: true
},
'/start-generate-stream': {
target: 'http://localhost:6969',
changeOrigin: true
},
'/get-generate-stream-output': {
target: 'http://localhost:6969',
},
'/predict-tags': {
target: 'http://localhost:6969',
changeOrigin: true
},
'/task-info': {
target: 'http://localhost:6969',
changeOrigin: true,
ws: true
},
}
const port = parseInt(process.env.PORT, 10) || 3000
const dev = process.env.NODE_ENV !== 'production'
const app = next({
dev
})
const handle = app.getRequestHandler()
app.prepare()
.then(() => {
const server = express()
if (dev && devProxy) {
Object.keys(devProxy).forEach(function(context) {
server.use(context, createProxyMiddleware(devProxy[context]))
})
}
server.all('*', (req, res) => {
handle(req, res)
})
server.listen(port, err => {
if (err) {
throw err
}
console.log(`> Ready on http://localhost:${port}`)
})
})
.catch(err => {
console.log('An error occurred, unable to start the server')
console.log(err)
})
Loading…
Cancel
Save