mirror of
https://github.com/Discreetly/server.git
synced 2026-01-09 12:37:58 -05:00
feat: configurable port/ws-port/name in .env
This commit is contained in:
@@ -3,19 +3,40 @@ import 'dotenv/config';
|
||||
|
||||
// TODO THIS SHOULD BE AN ENVIRONMENTAL VARIABLE STORED IN .env FILE
|
||||
// IF THIS FILE DOESN'T EXIST, GENERATE A RANDOM ID AND STORE IT IN THE FILE
|
||||
let server_ID: bigint;
|
||||
let SERVER_ID: bigint;
|
||||
let PORT: string;
|
||||
let WS_PORT: string;
|
||||
let NAME: string;
|
||||
|
||||
try {
|
||||
server_ID = process.env.SERVER_ID ? (process.env.SERVER_ID as unknown as bigint) : 0n;
|
||||
SERVER_ID = process.env.SERVER_ID ? (process.env.SERVER_ID as unknown as bigint) : 0n;
|
||||
} catch (error) {
|
||||
console.error('Error reading serverID from .env file!');
|
||||
}
|
||||
console.log('SERVERID:', server_ID);
|
||||
console.log('SERVERID:', SERVER_ID);
|
||||
|
||||
try {
|
||||
PORT = process.env.PORT ? process.env.PORT : '3001';
|
||||
} catch (err) {
|
||||
console.error('Error reading PORT from .env file!');
|
||||
}
|
||||
|
||||
try {
|
||||
WS_PORT = process.env.WS_PORT ? process.env.WS_PORT : '3002';
|
||||
} catch (err) {
|
||||
console.error('Error reading PORT from .env file!');
|
||||
}
|
||||
|
||||
try {
|
||||
NAME = process.env.NAME ? process.env.NAME : 'localhost';
|
||||
} catch (err) {
|
||||
console.error('Error reading PORT from .env file!');
|
||||
}
|
||||
|
||||
export const serverConfig: ServerI = {
|
||||
id: server_ID,
|
||||
name: 'Localhost',
|
||||
serverInfoEndpoint: 'localhost:3001',
|
||||
messageHandlerSocket: 'localhost:3002',
|
||||
id: SERVER_ID,
|
||||
name: NAME,
|
||||
serverInfoEndpoint: PORT,
|
||||
messageHandlerSocket: WS_PORT,
|
||||
version: '0.0.1'
|
||||
};
|
||||
|
||||
@@ -46,8 +46,8 @@ const io = new SocketIOServer(socket_server, {
|
||||
});
|
||||
|
||||
function initAppListeners() {
|
||||
const expressServerPort = serverConfig.serverInfoEndpoint.split(':')[1];
|
||||
const socketServerPort = serverConfig.messageHandlerSocket.split(':')[1];
|
||||
const expressServerPort = serverConfig.serverInfoEndpoint;
|
||||
const socketServerPort = serverConfig.messageHandlerSocket;
|
||||
app.listen(expressServerPort, () => {
|
||||
pp(`Express Http Server is running at port ${expressServerPort}`);
|
||||
});
|
||||
@@ -62,6 +62,7 @@ function initAppListeners() {
|
||||
*/
|
||||
if (!process.env.NODE_ENV || process.env.NODE_ENV === 'development') {
|
||||
console.log('~~~~DEVELOPMENT MODE~~~~');
|
||||
console.log(serverConfig);
|
||||
initWebsockets(io);
|
||||
initEndpoints(app, adminAuth);
|
||||
listEndpoints(app);
|
||||
|
||||
Reference in New Issue
Block a user