You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
naifu-frontend/dev-server.js

60 lines
1.5 KiB
JavaScript

// 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)
})