Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

Commit

Permalink
Merge pull request #12 from ConjureLabs/routes.js
Browse files Browse the repository at this point in the history
change to .routes.json config, and support .routes.js
  • Loading branch information
tmarshall authored Aug 1, 2020
2 parents 500e605 + f6e12e4 commit 2e53789
Show file tree
Hide file tree
Showing 15 changed files with 76 additions and 7 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ const route = new Route({
})
```
You can also set these in `routes.json` files in the route tree. Configuration is resolved, and any inline configuration will override resolved values.
You can also set these in `routes.json` or `routes.js` files in the route tree. Configuration is resolved, and any inline configuration will override resolved values.
```
.
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@conjurelabs/route",
"version": "1.1.0",
"version": "1.2.0",
"description": "Express routes made easy",
"main": "index.js",
"scripts": {
Expand Down
10 changes: 5 additions & 5 deletions sync-crawl.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const defaultVerbLookup = {
}
const startingDollarSign = /^\$/
const jsFileExt = /\.js$/
const confFile = /^routes.json$/i
const confFile = /^\.routes\.js(?:on)?$/i

class Logging {
constructor() {
Expand Down Expand Up @@ -126,13 +126,13 @@ function syncCrawlRoutesDir(rootpath, options = {}) {
const stat = fs.statSync(path.resolve(dirPath, resource))

if (stat.isFile()) {
if (jsFileExt.test(resource)) {
files.push(resource)
if (confFile.test(resource)) {
confPaths = confPaths.concat(path.resolve(dirPath, resource))
continue
}

if (confFile.test(resource)) {
confPaths = confPaths.concat(path.resolve(dirPath, resource))
if (jsFileExt.test(resource)) {
files.push(resource)
continue
}
}
Expand Down
3 changes: 3 additions & 0 deletions test/sync-crawl/helpers/routes-12/.routes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
wildcard: true
}
9 changes: 9 additions & 0 deletions test/sync-crawl/helpers/routes-12/with-wildcard/get.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const Route = require('../../../../../')

const r = new Route()

r.push((req, res) => {
res.send('TOP')
})

module.exports = r
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const Route = require('../../../../../../')

const r = new Route()

r.push((req, res) => {
res.send('SPECIFIC')
})

module.exports = r
3 changes: 3 additions & 0 deletions test/sync-crawl/helpers/routes-12/without-wildcard/.routes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
wildcard: false
}
9 changes: 9 additions & 0 deletions test/sync-crawl/helpers/routes-12/without-wildcard/get.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const Route = require('../../../../../')

const r = new Route()

r.push((req, res) => {
res.send('TOP')
})

module.exports = r
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const Route = require('../../../../../../')

const r = new Route()

r.push((req, res) => {
res.send('SPECIFIC')
})

module.exports = r
27 changes: 27 additions & 0 deletions test/sync-crawl/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -433,3 +433,30 @@ test('should go throuh sepcific routes before param routes (II)', t => {
}
})
})

test('should honor multiple of one verb, ordered (IV)', t => {
const router = new Router()
router.use(crawl('routes-12'))

router.handle({ url: '/without-wildcard/more-specific', method: 'GET' }, {
send: val => {
t.is(val, 'SPECIFIC')
}
})
router.handle({ url: '/without-wildcard', method: 'GET' }, {
send: val => {
t.is(val, 'TOP')
}
})

router.handle({ url: '/with-wildcard/more-specific', method: 'GET' }, {
send: val => {
t.is(val, 'TOP')
}
})
router.handle({ url: '/with-wildcard', method: 'GET' }, {
send: val => {
t.is(val, 'TOP')
}
})
})

0 comments on commit 2e53789

Please sign in to comment.