Attempting to resolve what I think is out of order issue
All checks were successful
Publish to Private NPM Registry / publish (push) Successful in 25s
All checks were successful
Publish to Private NPM Registry / publish (push) Successful in 25s
This commit is contained in:
parent
fe5b7964d7
commit
b965b53668
4 changed files with 17 additions and 12 deletions
|
|
@ -40,13 +40,12 @@ export class App {
|
|||
this.initializer = new Initializer();
|
||||
}
|
||||
|
||||
await this.initializer.init();
|
||||
|
||||
if(includeComponentLibrary) {
|
||||
const componentsLibraryMiddleware = await useComponentsLibrary({ expressApp: this.getExpressApp() }) as RequestHandler;
|
||||
this.getExpressApp().use(componentsLibraryMiddleware);
|
||||
this.initializer.addMiddleware(async () => await useComponentsLibrary<RequestHandler>({ expressApp: this.getExpressApp() }));
|
||||
}
|
||||
|
||||
await this.initializer.init();
|
||||
|
||||
// Start the server
|
||||
const port = process.env.PORT || this.DEFAULT_PORT;
|
||||
this.getExpressApp().listen(port, async () => {
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ export class Initializer {
|
|||
private view?: { filesPath: string, engine?: string };
|
||||
|
||||
/** The middlewares to use */
|
||||
private middlewares: ((...args: any[]) => RequestHandler)[];
|
||||
private middlewares: ((...args: any[]) => RequestHandler | Promise<RequestHandler>)[];
|
||||
|
||||
private app?: Application;
|
||||
private router?: Router;
|
||||
|
|
@ -42,7 +42,7 @@ export class Initializer {
|
|||
* @param inputs.view.filesPath The path to the view files
|
||||
* @param middlewares Th middlewares to use
|
||||
*/
|
||||
constructor(inputs?: { controllersPath?: string, staticFilesPath?: string, view?: { filesPath: string, engine?: string } }, ...middlewares: ((...args: any[]) => RequestHandler)[]) {
|
||||
constructor(inputs?: { controllersPath?: string, staticFilesPath?: string, view?: { filesPath: string, engine?: string } }, ...middlewares: ((...args: any[]) => RequestHandler | Promise<RequestHandler>)[]) {
|
||||
this.controllersPath = typeof inputs !== 'undefined' && inputs.controllersPath !== 'undefined' ? inputs.controllersPath : undefined;
|
||||
this.staticFilesPath = typeof inputs !== 'undefined' && inputs.staticFilesPath !== 'undefined' ? inputs.staticFilesPath : undefined;
|
||||
this.view = typeof inputs !== 'undefined' && typeof inputs.view !== 'undefined' ? inputs.view : undefined;
|
||||
|
|
@ -66,6 +66,10 @@ export class Initializer {
|
|||
return this.router;
|
||||
}
|
||||
|
||||
addMiddleware(...middlewares: ((...args: any[]) => RequestHandler | Promise<RequestHandler>)[]) {
|
||||
this.middlewares.push(...middlewares);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the Express app
|
||||
*
|
||||
|
|
@ -84,7 +88,9 @@ export class Initializer {
|
|||
* @param app The Express app to setup the middleware on
|
||||
*/
|
||||
private async setupMiddleware(app: Application) {
|
||||
this.middlewares.forEach(middleware => app.use(middleware()));
|
||||
for (const middleware of this.middlewares) {
|
||||
app.use(await middleware());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue