mirror of
https://github.com/AlecM33/Werewolf.git
synced 2025-12-26 07:47:50 +01:00
further refactor entrypoint, change 404 message
This commit is contained in:
@@ -25,7 +25,7 @@
|
||||
<div id="not-found-container">
|
||||
<h1>404</h1>
|
||||
<h3>The game or other resource that you are looking for could not be found, or you don't have permission to access it.
|
||||
If this error is unexpected, the application may have restarted.</h3>
|
||||
Old games are periodically cleared.</h3>
|
||||
</div>
|
||||
<script src="/dist/notFound-bundle.js"></script>
|
||||
</body>
|
||||
|
||||
27
index.js
27
index.js
@@ -4,37 +4,31 @@
|
||||
const express = require('express');
|
||||
const app = express();
|
||||
const ServerBootstrapper = require('./server/modules/ServerBootstrapper');
|
||||
const timerManager = require('./server/modules/singletons/TimerManager');
|
||||
const GameManager = require('./server/modules/singletons/GameManager');
|
||||
const eventManager = require('./server/modules/singletons/EventManager');
|
||||
const globals = require('./server/config/globals');
|
||||
const args = ServerBootstrapper.processCLIArgs();
|
||||
const logger = require('./server/modules/Logger')(args.logLevel);
|
||||
const port = parseInt(process.env.PORT) || args.port || 8080;
|
||||
const webServer = ServerBootstrapper.createServerWithCorrectHTTPProtocol(app, args.useHttps, args.port, logger);
|
||||
const instanceId = (() => {
|
||||
const webServer = ServerBootstrapper.createServerWithCorrectHTTPProtocol(app, args.useHttps, port, logger);
|
||||
const singletons = ServerBootstrapper.singletons(logger, (() => {
|
||||
let id = '';
|
||||
for (let i = 0; i < globals.INSTANCE_ID_LENGTH; i ++) {
|
||||
id += globals.INSTANCE_ID_CHAR_POOL[Math.floor(Math.random() * globals.INSTANCE_ID_CHAR_POOL.length)];
|
||||
}
|
||||
return id;
|
||||
})()
|
||||
const singletons = ServerBootstrapper.singletons(logger, instanceId);
|
||||
})());
|
||||
ServerBootstrapper.injectDependencies(singletons);
|
||||
|
||||
app.use(express.json({limit: '10kb'}));
|
||||
|
||||
logger.info('LOG LEVEL IS: ' + args.logLevel);
|
||||
|
||||
singletons.gameManager.timerManager = timerManager.instance;
|
||||
singletons.gameManager.eventManager = eventManager.instance;
|
||||
singletons.eventManager.timerManager = timerManager.instance;
|
||||
singletons.eventManager.gameManager = GameManager.instance;
|
||||
|
||||
await singletons.eventManager.createRedisPublisher();
|
||||
await singletons.eventManager.createGameSyncSubscriber(singletons.gameManager, singletons.eventManager);
|
||||
|
||||
const socketServer = singletons.eventManager.createSocketServer(webServer, app, port);
|
||||
singletons.gameManager.setGameSocketNamespace(singletons.eventManager.createGameSocketNamespace(socketServer, logger, singletons.gameManager));
|
||||
singletons.gameManager.setGameSocketNamespace(
|
||||
singletons.eventManager.createGameSocketNamespace(socketServer, logger, singletons.gameManager)
|
||||
);
|
||||
ServerBootstrapper.establishRouting(app, express);
|
||||
|
||||
app.set('port', port);
|
||||
@@ -44,8 +38,11 @@
|
||||
webServer.listen(app.get('port'), () => {
|
||||
logger.info(`Starting server on port ${app.get('port')}`);
|
||||
resolve();
|
||||
});
|
||||
}).on('error', reject);
|
||||
});
|
||||
})();
|
||||
})().then(() => console.log('Server startup complete.'))
|
||||
.catch((e) => console.error('SERVER FAILED TO START: ' + e));
|
||||
.catch((e) => {
|
||||
console.error('SERVER FAILED TO START: ' + e);
|
||||
process.exit(-1);
|
||||
});
|
||||
|
||||
@@ -22,6 +22,16 @@ const ServerBootstrapper = {
|
||||
};
|
||||
},
|
||||
|
||||
injectDependencies: (singletons) => {
|
||||
const timerManager = require('./singletons/TimerManager').instance;
|
||||
const gameManager = require('./singletons/GameManager').instance;
|
||||
const eventManager = require('./singletons/EventManager').instance;
|
||||
singletons.gameManager.timerManager = timerManager;
|
||||
singletons.gameManager.eventManager = eventManager;
|
||||
singletons.eventManager.timerManager = timerManager;
|
||||
singletons.eventManager.gameManager = gameManager;
|
||||
},
|
||||
|
||||
processCLIArgs: () => {
|
||||
try {
|
||||
const args = Array.from(process.argv.map((arg) => arg.trim().toLowerCase()));
|
||||
|
||||
Reference in New Issue
Block a user