Changed the framework so that apps out of the box come with the Bridgeman Accessible Web Components library (which if not used introduces little latency but if used provide large value)
All checks were successful
Publish to Private NPM Registry / publish (push) Successful in 34s
All checks were successful
Publish to Private NPM Registry / publish (push) Successful in 34s
This commit is contained in:
parent
7f9506279f
commit
5a18653c69
5 changed files with 36 additions and 11 deletions
12
src/App.ts
12
src/App.ts
|
|
@ -1,6 +1,7 @@
|
|||
import 'reflect-metadata';
|
||||
import type { Application } from 'express';
|
||||
import type { RequestHandler } from 'express';
|
||||
|
||||
import useComponentsLibrary from '@BridgemanAccessible/ba-web-components';
|
||||
import { logMessage, LogLevel } from '@BridgemanAccessible/ba-logging';
|
||||
|
||||
import { Initializer } from './Initializer.js';
|
||||
|
|
@ -30,7 +31,7 @@ export class App {
|
|||
* The main entry point for the web app
|
||||
* This is mostly required because of async/await
|
||||
*/
|
||||
async run<T extends Initializer>(initializer?: T, callback?: (app: App) => void | Promise<void>, onErrorCallback?: (error: any) => void | Promise<void>) {
|
||||
async run<T extends Initializer>(initializer?: T, callback?: (app: App) => void | Promise<void>, onErrorCallback?: (error: any) => void | Promise<void>, includeComponentLibrary: boolean = true): Promise<void> {
|
||||
// Do the initial setup of the app
|
||||
if(typeof initializer !== 'undefined') {
|
||||
this.initializer = initializer;
|
||||
|
|
@ -41,11 +42,16 @@ export class App {
|
|||
|
||||
await this.initializer.init();
|
||||
|
||||
if(includeComponentLibrary) {
|
||||
const componentsLibraryMiddleware = await useComponentsLibrary({ expressApp: this.getExpressApp() }) as RequestHandler;
|
||||
this.getExpressApp().use(componentsLibraryMiddleware);
|
||||
}
|
||||
|
||||
// Start the server
|
||||
const port = process.env.PORT || this.DEFAULT_PORT;
|
||||
this.getExpressApp().listen(port, async () => {
|
||||
logMessage(`Server is running on port ${port}`, LogLevel.DEBUG);
|
||||
|
||||
|
||||
// Run the callback if one is provided
|
||||
if(typeof callback !== 'undefined') {
|
||||
await callback.bind(this)(this);
|
||||
|
|
|
|||
|
|
@ -1,5 +1,3 @@
|
|||
import axios from 'axios';
|
||||
|
||||
import { Scopes } from '@BridgemanAccessible/ba-auth';
|
||||
import Client from '@BridgemanAccessible/ba-auth/client';
|
||||
import type { OnAuthCallback } from '@BridgemanAccessible/ba-auth/client';
|
||||
|
|
@ -321,6 +319,7 @@ export class OAuthApp<TCustomClaims extends BridgemanAccessibleAppClaims, TScope
|
|||
* It's done this way so that it's almost entirely transparent the difference between apps that have OAuth and those that don't.
|
||||
*
|
||||
* @param app The Express app object (that is now listening)
|
||||
* @param callback The callback to call after setting up the OAuth client (this is the `onStart` callback provided to the `run` method)
|
||||
*/
|
||||
private async onStart(app: App, callback?: (app: OAuthApp<TCustomClaims, TScopes>) => void | Promise<void>) {
|
||||
try {
|
||||
|
|
@ -370,7 +369,7 @@ export class OAuthApp<TCustomClaims extends BridgemanAccessibleAppClaims, TScope
|
|||
* And doesn't have to worry about the OAuth details to make this work.
|
||||
* Though it does provide tweaking the OAuth details via options provided to the constructor.
|
||||
*/
|
||||
async run<T extends Initializer>(initializer?: T, callback?: (app: OAuthApp<TCustomClaims, TScopes>) => void | Promise<void>) {
|
||||
await super.run(initializer, async (app: App) => this.onStart(app, callback));
|
||||
async run<T extends Initializer>(initializer?: T, callback?: (app: OAuthApp<TCustomClaims, TScopes>) => void | Promise<void>, onErrorCallback?: (error: any) => void | Promise<void>, includeComponentLibrary: boolean = true): Promise<void> {
|
||||
await super.run(initializer, async (app: App) => this.onStart(app, callback), onErrorCallback, includeComponentLibrary);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue