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