fix serve

This commit is contained in:
Simon Larsen
2022-12-08 08:16:30 +00:00
parent d7bcff99f9
commit d8a8a2d595
8 changed files with 46 additions and 19 deletions

View File

@@ -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'));
});

View File

@@ -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'"

View File

@@ -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<express.Application> {
return new Promise<express.Application>((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);

View File

@@ -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<ExpressApplication> => {
await Express.launchApplication(appName);
const init: Function = async (appName: string, port?: Port): Promise<ExpressApplication> => {
await Express.launchApplication(appName, port);
LocalCache.setString('app', 'name', appName);
CommonAPI(appName);

View File

@@ -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'));
});

View File

@@ -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'"

36
StatusPage/Serve.ts Normal file
View File

@@ -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<void> => {
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;

View File

@@ -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'"