port override in .env

This commit is contained in:
Erik 2023-07-15 20:24:01 +03:00
parent 5579d3866e
commit 1570f347f0
Signed by: Navy.gif
GPG Key ID: 2532FBBB61C65A68
2 changed files with 12 additions and 8 deletions

View File

@ -1,6 +1,6 @@
import { readFileSync } from "node:fs"; import { readFileSync } from 'node:fs';
import path from "node:path"; import path from 'node:path';
import process from "node:process"; import process from 'node:process';
const options = JSON.parse(readFileSync('./options.json', { encoding: 'utf-8' })); const options = JSON.parse(readFileSync('./options.json', { encoding: 'utf-8' }));
const segments = path.resolve(process.argv[0]).split('\\'); const segments = path.resolve(process.argv[0]).split('\\');
@ -12,7 +12,9 @@ const srcDir = path.join(resolved, 'src');
const controllerDir = path.join(srcDir, 'controller'); const controllerDir = path.join(srcDir, 'controller');
options.srcDir = srcDir; options.srcDir = srcDir;
import { Controller } from "./src/controller/index.js"; import { Controller } from './src/controller/index.js';
import dotenv from 'dotenv'; import dotenv from 'dotenv';
const controller = new Controller(controllerDir, { ...options, env: dotenv.config().parsed }); const env = dotenv.config().parsed;
const controller = new Controller(controllerDir, { ...options, env });
controller.init(); controller.init();

View File

@ -85,7 +85,8 @@ class Server extends EventEmitter
NODE_ENV, SECRET, CRYPTO_SECRET, CRYPTO_SALT, NODE_ENV, SECRET, CRYPTO_SECRET, CRYPTO_SALT,
MONGO_MEMORY_URI, MONGO_MEMORY_HOST, MONGO_MEMORY_USER, MONGO_MEMORY_PORT, MONGO_MEMORY_URI, MONGO_MEMORY_HOST, MONGO_MEMORY_USER, MONGO_MEMORY_PORT,
MONGO_MEMORY_PASS, MONGO_MEMORY_DB, MONGO_MEMORY_AUTH_DB, MONGO_MEMORY_PASS, MONGO_MEMORY_DB, MONGO_MEMORY_AUTH_DB,
RABBIT_HOST, RABBIT_USER, RABBIT_PASS, RABBIT_VHOST, RABBIT_PORT RABBIT_HOST, RABBIT_USER, RABBIT_PASS, RABBIT_VHOST, RABBIT_PORT,
PORT
} = process.env as { [key: string]: string }; } = process.env as { [key: string]: string };
const { http: httpOpts, databases, name } = options; const { http: httpOpts, databases, name } = options;
@ -107,7 +108,8 @@ class Server extends EventEmitter
this.#logger = new LoggerClient({ ...options.logger, name: this.constructor.name }); this.#logger = new LoggerClient({ ...options.logger, name: this.constructor.name });
// Port number is automatically incremented based on shard # // Port number is automatically incremented based on shard #
this.#port = httpOpts.port + this.#shardId; const _port = parseInt(PORT);
this.#port = isNaN(_port) ? httpOpts.port + this.#shardId : _port;
// Primarily used by the OAuth methods for the callback url // Primarily used by the OAuth methods for the callback url
if (NODE_ENV === 'development') if (NODE_ENV === 'development')
{ {
@ -240,7 +242,7 @@ class Server extends EventEmitter
} }
async init () async init (): Promise<void>
{ {
if (this.#_ready) if (this.#_ready)
return void this.#logger.warn('Server already initialised!'); return void this.#logger.warn('Server already initialised!');