From 0b96c79ccd562b1ba31e03da7e202750a72d9198 Mon Sep 17 00:00:00 2001 From: Lex Lim Date: Sat, 22 Oct 2022 09:10:21 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=BC=80=E5=8F=91=E6=A8=A1?= =?UTF-8?q?=E5=BC=8F=E4=BB=A3=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dev-server.js | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 dev-server.js diff --git a/dev-server.js b/dev-server.js new file mode 100644 index 0000000..a3c7f59 --- /dev/null +++ b/dev-server.js @@ -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) + }) \ No newline at end of file