initial commit
This commit is contained in:
63
server/index.js
Normal file
63
server/index.js
Normal file
@@ -0,0 +1,63 @@
|
||||
import ParcelCore from "@parcel/core";
|
||||
const { default: Parcel } = ParcelCore;
|
||||
|
||||
import { createProxyMiddleware } from 'http-proxy-middleware';
|
||||
import express from "express";
|
||||
import { createRequire } from "module";
|
||||
import path from 'path';
|
||||
import { fileURLToPath } from 'url';
|
||||
import config from "../config.js";
|
||||
import MhdMapApp from "./MhdMapApp.js";
|
||||
import SocketHandler from "./SocketHandler.js";
|
||||
|
||||
const __filename = fileURLToPath(import.meta.url);
|
||||
const __dirname = path.dirname(__filename);
|
||||
|
||||
const devPort = 5000;
|
||||
const servicePort = 5001;
|
||||
const staticFilePath = './static'
|
||||
|
||||
// Development Server Settings
|
||||
const frontEndDevServerOptions = {
|
||||
defaultConfig: createRequire(import.meta.url).resolve(
|
||||
"@parcel/config-default"
|
||||
),
|
||||
entries: path.join(__dirname, '../client/index.html'),
|
||||
mode: 'development',
|
||||
logLevel: 4,
|
||||
serveOptions: {
|
||||
port: devPort,
|
||||
},
|
||||
/* hmrOptions: {
|
||||
port: devPort,
|
||||
}, */
|
||||
publicUrl: config.urlPrefix,
|
||||
defaultTargetOptions: {
|
||||
publicUrl: config.urlPrefix,
|
||||
},
|
||||
};
|
||||
|
||||
const bundler = new Parcel(frontEndDevServerOptions);
|
||||
(async () => {
|
||||
await bundler.watch();
|
||||
})();
|
||||
|
||||
const server = express();
|
||||
const socketHandler = new SocketHandler(config.urlPrefix + '/ws');
|
||||
socketHandler.start(server);
|
||||
|
||||
const app = new MhdMapApp(socketHandler);
|
||||
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.
|
||||
});
|
||||
server.use('/', parcelMiddleware);
|
||||
|
||||
// Run your Express server
|
||||
server.listen(servicePort, () => {
|
||||
console.log(`Listening to port ${servicePort}...`);
|
||||
});
|
||||
Reference in New Issue
Block a user