diff --git a/lib/ExpressSpool.ts b/lib/ExpressSpool.ts index 62b8ae4..5359828 100644 --- a/lib/ExpressSpool.ts +++ b/lib/ExpressSpool.ts @@ -63,7 +63,7 @@ export class ExpressSpool extends ServerSpool { // Set a config that let's other spools know this is using express as a webserver this.app.config.set('web.server', 'express') // Set helmet for express if it is not explicitly disabled - if (this.app.config.get('express.helmet') === false) { + if (this.app.config.get('express.helmet') !== false) { this.app.config.set('web.middlewares.helmet', helmet(this.app.config.get('express.helmet'))) } } @@ -124,5 +124,11 @@ export class ExpressSpool extends ServerSpool { if (!(this.app.routes instanceof Object)) { throw new Error('Sanity Failed: app.routes is not an object!') } + if ( + this.app.config.get('express.helmet') !== false + && !this.app.config.get('web.middlewares.helmet') + ) { + throw new Error('Sanity Failed: Helmet was not set on web.middlware when configured at express.helmet') + } } } diff --git a/lib/server.ts b/lib/server.ts index 4c693e7..305559b 100755 --- a/lib/server.ts +++ b/lib/server.ts @@ -23,7 +23,7 @@ export interface Server { export const Server: Server = { BreakException: {}, - port: null, + port: null, // process.env.PORT, portHttp: null, host: null, ssl: null, @@ -46,6 +46,7 @@ export const Server: Server = { } const server = express() + this.webConfig = Object.assign({}, app.config.get('web')) this.middlewares = app.config.get('web.middlewares') || {} this.middlewaresOrder = Object.values(app.config.get('web.middlewares.order') || []) @@ -365,6 +366,7 @@ export const Server: Server = { } }) server.use(router) + return router }, /** @@ -388,7 +390,7 @@ export const Server: Server = { const promises = Array.from(this.nativeServers.values()) .map((s) => { - return Server.listenPromise(s) + return Server.listenPromise(app, s) }) return Promise.all(promises) @@ -423,19 +425,20 @@ export const Server: Server = { this.nativeServers.set('http', { server: http.createServer(server), host: this.host, - port: this.portHttp, + port: this.portHttp || this.port, }) return resolve() } }) }, - listenPromise(config: {host: string, port: number, server: any}) { + listenPromise(app: FabrixApp, config: {host: string, port: number, server: any}) { return new Promise((resolve, reject) => { config.server.listen(config.port, config.host, function (err) { if (err) { reject(err) } + app.log.info(`express: ${config.host} listening on ${config.port}`) resolve() }) }) diff --git a/package-lock.json b/package-lock.json index d185614..3a32843 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "@fabrix/spool-express", - "version": "1.6.2", + "version": "1.6.3", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 24c9e0d..7c4b9cf 100755 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@fabrix/spool-express", - "version": "1.6.2", + "version": "1.6.3", "description": "Spool Express - Binds the routes compiled in spool-router to an Express 4 Server.", "homepage": "https://fabrix.app", "author": {