diff --git a/Accounts/Index.ts b/Accounts/Serve.ts similarity index 87% rename from Accounts/Index.ts rename to Accounts/Serve.ts index 63f8754d0e..89657b1ae6 100755 --- a/Accounts/Index.ts +++ b/Accounts/Serve.ts @@ -16,11 +16,6 @@ app.use(ExpressStatic(path.join(__dirname, 'public'))); app.use(`/${APP_NAME}`, ExpressStatic(path.join(__dirname, 'public'))); -app.use( - [`/${APP_NAME}/assets`, `/${APP_NAME}/${APP_NAME}/assets`], - ExpressStatic(path.join(__dirname, 'dist')) -); - app.get('/*', (_req: ExpressRequest, res: ExpressResponse) => { res.sendFile(path.join(__dirname, 'public', 'index.html')); }); diff --git a/Accounts/package.json b/Accounts/package.json index 61895c0f49..c2cbacfb88 100644 --- a/Accounts/package.json +++ b/Accounts/package.json @@ -22,7 +22,7 @@ "build": "webpack build --mode=production", "test": "", "compile": "tsc", - "start": "node --require ts-node/register Index.ts", + "start": "node --require ts-node/register Serve.ts", "audit": "npm audit --audit-level=low", "preinstall": "npx npm-force-resolutions || echo 'No package-lock.json file. Skipping force resolutions'", "dep-check": "depcheck ./ --skip-missing=true'" diff --git a/CommonServer/Utils/Express.ts b/CommonServer/Utils/Express.ts index 8a8a7dd918..0eef23cbd8 100644 --- a/CommonServer/Utils/Express.ts +++ b/CommonServer/Utils/Express.ts @@ -10,6 +10,7 @@ import { } from 'Common/Types/Permission'; import UserType from 'Common/Types/UserType'; import Dictionary from 'Common/Types/Dictionary'; +import Port from 'Common/Types/Port'; export type RequestHandler = express.RequestHandler; export type NextFunction = express.NextFunction; @@ -63,14 +64,14 @@ class Express { } public static async launchApplication( - appName: string + appName: string, port?: Port ): Promise { return new Promise((resolve: Function) => { if (!this.app) { this.setupExpress(); } - this.app.listen(this.app.get('port'), () => { + this.app.listen(port?.toNumber() || this.app.get('port'), () => { // eslint-disable-next-line logger.info(`${appName} server started on port: ${this.app.get('port')}`); return resolve(this.app); diff --git a/CommonServer/Utils/StartServer.ts b/CommonServer/Utils/StartServer.ts index 0354f2a3a3..34c8e9da05 100644 --- a/CommonServer/Utils/StartServer.ts +++ b/CommonServer/Utils/StartServer.ts @@ -2,7 +2,7 @@ import './Envrionment'; import './Process'; import logger from './Logger'; import cors from 'cors'; - +import Port from 'Common/Types/Port'; import Express, { ExpressRequest, ExpressResponse, @@ -89,8 +89,8 @@ app.use(ExpressUrlEncoded({ limit: '50mb' })); app.use(logRequest); -const init: Function = async (appName: string): Promise => { - await Express.launchApplication(appName); +const init: Function = async (appName: string, port?: Port): Promise => { + await Express.launchApplication(appName, port); LocalCache.setString('app', 'name', appName); CommonAPI(appName); diff --git a/Dashboard/Index.ts b/Dashboard/Serve.ts similarity index 82% rename from Dashboard/Index.ts rename to Dashboard/Serve.ts index a0c01f94df..89657b1ae6 100755 --- a/Dashboard/Index.ts +++ b/Dashboard/Serve.ts @@ -8,7 +8,7 @@ import Express, { } from 'CommonServer/Utils/Express'; import logger from 'CommonServer/Utils/Logger'; -export const APP_NAME: string = 'dashboard'; +export const APP_NAME: string = 'accounts'; const app: ExpressApplication = Express.getExpressApp(); @@ -16,11 +16,6 @@ app.use(ExpressStatic(path.join(__dirname, 'public'))); app.use(`/${APP_NAME}`, ExpressStatic(path.join(__dirname, 'public'))); -app.use( - [`/${APP_NAME}/assets`, `/${APP_NAME}/${APP_NAME}/assets`], - ExpressStatic(path.join(__dirname, 'dist')) -); - app.get('/*', (_req: ExpressRequest, res: ExpressResponse) => { res.sendFile(path.join(__dirname, 'public', 'index.html')); }); diff --git a/Dashboard/package.json b/Dashboard/package.json index ff98ae70b5..264e19f995 100644 --- a/Dashboard/package.json +++ b/Dashboard/package.json @@ -27,7 +27,7 @@ "test": "react-app-rewired test", "eject": "webpack eject", "compile": "tsc", - "start": "node --require ts-node/register Index.ts", + "start": "node --require ts-node/register Serve.ts", "audit": "npm audit --audit-level=low", "preinstall": "npx npm-force-resolutions || echo 'No package-lock.json file. Skipping force resolutions'", "dep-check": "depcheck ./ --skip-missing=true'" diff --git a/StatusPage/Serve.ts b/StatusPage/Serve.ts new file mode 100644 index 0000000000..0455db4dcd --- /dev/null +++ b/StatusPage/Serve.ts @@ -0,0 +1,36 @@ +import App from 'CommonServer/Utils/StartServer'; +import path from 'path'; +import Express, { + ExpressApplication, + ExpressRequest, + ExpressResponse, + ExpressStatic, +} from 'CommonServer/Utils/Express'; +import logger from 'CommonServer/Utils/Logger'; +import Port from 'Common/Types/Port'; + +export const APP_NAME: string = 'accounts'; + +const app: ExpressApplication = Express.getExpressApp(); + +app.use(ExpressStatic(path.join(__dirname, 'public'))); + +app.use(`/${APP_NAME}`, ExpressStatic(path.join(__dirname, 'public'))); + +app.get('/*', (_req: ExpressRequest, res: ExpressResponse) => { + res.sendFile(path.join(__dirname, 'public', 'index.html')); +}); + +const init: Function = async (): Promise => { + try { + // init the app + await App(APP_NAME, new Port(3106)); + } catch (err) { + logger.error('App Init Failed:'); + logger.error(err); + } +}; + +init(); + +export default app; diff --git a/StatusPage/package.json b/StatusPage/package.json index 3decd6a848..424866d885 100644 --- a/StatusPage/package.json +++ b/StatusPage/package.json @@ -25,7 +25,7 @@ "test": "react-app-rewired test", "eject": "webpack eject", "compile": "tsc", - "start": "http-server ./public -p 3105 & node --require ts-node/register Index.ts", + "start": "node --require ts-node/register Serve.ts & node --require ts-node/register Index.ts", "audit": "npm audit --audit-level=low", "preinstall": "npx npm-force-resolutions || echo 'No package-lock.json file. Skipping force resolutions'", "dep-check": "depcheck ./ --skip-missing=true'"