Skip to content

Commit

Permalink
[fix] insure that app.routes results in an array
Browse files Browse the repository at this point in the history
  • Loading branch information
scott-wyatt committed Jul 16, 2018
1 parent 703672a commit 624a339
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 11 deletions.
14 changes: 10 additions & 4 deletions lib/RouterSpool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,18 @@ export class RouterSpool extends SystemSpool {
}

async validate () {
if (!this.app.config.get('router')) {
this.app.log.warn('Missing config.router, a default empty configuration will be used')
}
if (!this.app.config.get('routes')) {
this.app.log.warn('Missing config.routes, a default empty Array will be used')
}
return Promise.all([
Validator.validateRouter(this.app.config.get('router')),
Promise.all(
this.app.config.get('routes').map(Validator.validateRoute)
Object.values(this.app.config.get('routes') || []).map(Validator.validateRoute)
),
Validator.validateRouteList(this.app.config.get('routes'))
Validator.validateRouteList(Object.values(this.app.config.get('routes') || []))
])
}

Expand All @@ -67,9 +73,9 @@ export class RouterSpool extends SystemSpool {
* automatically merged into the application's config.routes list.
*/
async initialize () {
const routes = this.app.config.get('routes') || []
const routes = Object.values(this.app.config.get('routes') || [])
this._routes = routes
.map(route => Utils.buildRoute(this.app, route))
.map((route: {[key: string]: any}) => Utils.buildRoute(this.app, route))
.filter(route => !!route)
.sort(Utils.createSpecificityComparator({ order: this.app.config.get('router.sortOrder') }))
}
Expand Down
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@fabrix/spool-router",
"version": "1.0.0",
"version": "1.0.1",
"description": "Spool - Router for Fabrix",
"scripts": {
"build": "tsc -p ./lib/tsconfig.release.json",
Expand Down Expand Up @@ -49,7 +49,7 @@
"lodash": "^4.17.10"
},
"devDependencies": {
"@fabrix/fabrix": "^1.0.1",
"@fabrix/fabrix": "^1.0.8",
"@fabrix/lint": "^1.0.0-alpha.3",
"@types/lodash": "^4.14.109",
"@types/node": "~10.3.4",
Expand All @@ -64,7 +64,7 @@
"typescript": "~2.8.1"
},
"peerDependencies": {
"@fabrix/fabrix": "^1.0.1"
"@fabrix/fabrix": "^1.0.8"
},
"license": "MIT",
"bugs": {
Expand Down

0 comments on commit 624a339

Please sign in to comment.