(
@inject(CoreBindings.APPLICATION_CONFIG.deepProperty('express'))
protected readonly config?: ExpressServerConfig,
@inject(CoreBindings.APPLICATION_INSTANCE)
parent?: Context,
)
| 51 | */ |
| 52 | protected httpServer: HttpServer; |
| 53 | constructor( |
| 54 | @inject(CoreBindings.APPLICATION_CONFIG.deepProperty('express')) |
| 55 | protected readonly config?: ExpressServerConfig, |
| 56 | @inject(CoreBindings.APPLICATION_INSTANCE) |
| 57 | parent?: Context, |
| 58 | ) { |
| 59 | super(parent); |
| 60 | this.scope = BindingScope.SERVER; |
| 61 | let basePath = config?.basePath ?? ''; |
| 62 | // Trim leading and trailing `/` |
| 63 | basePath = basePath.replace(/(^\/)|(\/$)/, ''); |
| 64 | if (basePath) basePath = '/' + basePath; |
| 65 | this.basePath = basePath; |
| 66 | |
| 67 | this.expressApp = express(); |
| 68 | if (config?.settings) { |
| 69 | for (const p in config?.settings) { |
| 70 | this.expressApp.set(p, config?.settings[p]); |
| 71 | } |
| 72 | } |
| 73 | this.httpServer = new HttpServer(this.expressApp, config); |
| 74 | |
| 75 | // Set up the middleware chain as the 1st Express middleware |
| 76 | this.expressApp.use(this.basePath, toExpressMiddleware(this)); |
| 77 | } |
| 78 | |
| 79 | /** |
| 80 | * Some of the methods below are copied from RestServer |
nothing calls this directly
no test coverage detected