diff --git a/README.md b/README.md index 06dd758..b14307d 100644 --- a/README.md +++ b/README.md @@ -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. ``` . diff --git a/examples/custom-handlers/routes/routes.json b/examples/custom-handlers/routes/.routes.json similarity index 100% rename from examples/custom-handlers/routes/routes.json rename to examples/custom-handlers/routes/.routes.json diff --git a/examples/custom-handlers/routes/account/routes.json b/examples/custom-handlers/routes/account/.routes.json similarity index 100% rename from examples/custom-handlers/routes/account/routes.json rename to examples/custom-handlers/routes/account/.routes.json diff --git a/examples/custom-handlers/routes/debug/routes.json b/examples/custom-handlers/routes/debug/.routes.json similarity index 100% rename from examples/custom-handlers/routes/debug/routes.json rename to examples/custom-handlers/routes/debug/.routes.json diff --git a/package.json b/package.json index e48296a..00f7982 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@conjurelabs/route", - "version": "1.1.0", + "version": "1.2.0", "description": "Express routes made easy", "main": "index.js", "scripts": { diff --git a/sync-crawl.js b/sync-crawl.js index baf59f0..f24b9e2 100644 --- a/sync-crawl.js +++ b/sync-crawl.js @@ -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() { @@ -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 } } diff --git a/test/sync-crawl/helpers/routes-10/routes.json b/test/sync-crawl/helpers/routes-10/.routes.json similarity index 100% rename from test/sync-crawl/helpers/routes-10/routes.json rename to test/sync-crawl/helpers/routes-10/.routes.json diff --git a/test/sync-crawl/helpers/routes-10/without-wildcard/routes.json b/test/sync-crawl/helpers/routes-10/without-wildcard/.routes.json similarity index 100% rename from test/sync-crawl/helpers/routes-10/without-wildcard/routes.json rename to test/sync-crawl/helpers/routes-10/without-wildcard/.routes.json diff --git a/test/sync-crawl/helpers/routes-12/.routes.js b/test/sync-crawl/helpers/routes-12/.routes.js new file mode 100644 index 0000000..a640d57 --- /dev/null +++ b/test/sync-crawl/helpers/routes-12/.routes.js @@ -0,0 +1,3 @@ +module.exports = { + wildcard: true +} diff --git a/test/sync-crawl/helpers/routes-12/with-wildcard/get.js b/test/sync-crawl/helpers/routes-12/with-wildcard/get.js new file mode 100644 index 0000000..9086608 --- /dev/null +++ b/test/sync-crawl/helpers/routes-12/with-wildcard/get.js @@ -0,0 +1,9 @@ +const Route = require('../../../../../') + +const r = new Route() + +r.push((req, res) => { + res.send('TOP') +}) + +module.exports = r diff --git a/test/sync-crawl/helpers/routes-12/with-wildcard/more-specific/get.js b/test/sync-crawl/helpers/routes-12/with-wildcard/more-specific/get.js new file mode 100644 index 0000000..70fb58a --- /dev/null +++ b/test/sync-crawl/helpers/routes-12/with-wildcard/more-specific/get.js @@ -0,0 +1,9 @@ +const Route = require('../../../../../../') + +const r = new Route() + +r.push((req, res) => { + res.send('SPECIFIC') +}) + +module.exports = r diff --git a/test/sync-crawl/helpers/routes-12/without-wildcard/.routes.js b/test/sync-crawl/helpers/routes-12/without-wildcard/.routes.js new file mode 100644 index 0000000..0a68504 --- /dev/null +++ b/test/sync-crawl/helpers/routes-12/without-wildcard/.routes.js @@ -0,0 +1,3 @@ +module.exports = { + wildcard: false +} diff --git a/test/sync-crawl/helpers/routes-12/without-wildcard/get.js b/test/sync-crawl/helpers/routes-12/without-wildcard/get.js new file mode 100644 index 0000000..9086608 --- /dev/null +++ b/test/sync-crawl/helpers/routes-12/without-wildcard/get.js @@ -0,0 +1,9 @@ +const Route = require('../../../../../') + +const r = new Route() + +r.push((req, res) => { + res.send('TOP') +}) + +module.exports = r diff --git a/test/sync-crawl/helpers/routes-12/without-wildcard/more-specific/get.js b/test/sync-crawl/helpers/routes-12/without-wildcard/more-specific/get.js new file mode 100644 index 0000000..70fb58a --- /dev/null +++ b/test/sync-crawl/helpers/routes-12/without-wildcard/more-specific/get.js @@ -0,0 +1,9 @@ +const Route = require('../../../../../../') + +const r = new Route() + +r.push((req, res) => { + res.send('SPECIFIC') +}) + +module.exports = r diff --git a/test/sync-crawl/index.js b/test/sync-crawl/index.js index 6764b76..770a865 100644 --- a/test/sync-crawl/index.js +++ b/test/sync-crawl/index.js @@ -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') + } + }) +})