From 46c8883ea970cbe6343e3ed2112a4639b3c8c889 Mon Sep 17 00:00:00 2001 From: ericek111 Date: Tue, 13 Sep 2022 20:01:19 +0200 Subject: [PATCH] add ports to config + bind only to localhost --- config.sample.js | 2 ++ server/index.js | 18 +++++++++++------- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/config.sample.js b/config.sample.js index 6b02f7d..0982cde 100644 --- a/config.sample.js +++ b/config.sample.js @@ -1,4 +1,6 @@ const config = { + devPort: 15800, + servicePort: 15801, urlPrefix: "/mhd", openDataKey: 'INSERT_YOUR_OPENDATA_API_KEY_HERE', database: { diff --git a/server/index.js b/server/index.js index c8e2e47..a459501 100644 --- a/server/index.js +++ b/server/index.js @@ -13,8 +13,8 @@ import SocketHandler from "./SocketHandler.js"; const __filename = fileURLToPath(import.meta.url); const __dirname = path.dirname(__filename); -const devPort = 5000; -const servicePort = 5001; +const devPort = config.devPort; +const servicePort = config.servicePort; const staticFilePath = './static' // Development Server Settings @@ -26,6 +26,7 @@ const frontEndDevServerOptions = { mode: 'development', logLevel: 4, serveOptions: { + host: '127.0.0.1', port: devPort, }, /* hmrOptions: { @@ -51,13 +52,16 @@ app.start(); server.use(config.urlPrefix + '/static', express.static(staticFilePath)); -const parcelMiddleware = createProxyMiddleware({ - target: `http://localhost:${devPort}/`, - pathRewrite: {'^/mhd' : ''} // TODO: Maybe fix this with Parcel. -}); +const proxyCfg = { + target: `http://127.0.0.1:${devPort}/`, + pathRewrite: {}, +}; +proxyCfg.pathRewrite['^' + config.urlPrefix] = '/'; // TODO: Maybe fix this with Parcel + +const parcelMiddleware = createProxyMiddleware(proxyCfg); server.use('/', parcelMiddleware); // Run your Express server -server.listen(servicePort, () => { +server.listen(servicePort, '127.0.0.1', () => { console.log(`Listening to port ${servicePort}...`); });