initial commit

This commit is contained in:
2022-06-28 13:02:50 +02:00
commit a4e6b655b7
16 changed files with 7870 additions and 0 deletions

63
server/index.js Normal file
View 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}...`);
});