-
Notifications
You must be signed in to change notification settings - Fork 141
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
versioning as configurable option (#107)
- Loading branch information
1 parent
6b9b2d5
commit c69b04b
Showing
8 changed files
with
135 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
'use strict' | ||
|
||
const SemVerStore = require('semver-store') | ||
|
||
module.exports = { | ||
storage: SemVerStore, | ||
deriveVersion: function (req, ctx) { | ||
return req.headers['accept-version'] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
'use strict' | ||
|
||
const t = require('tap') | ||
const test = t.test | ||
const FindMyWay = require('../') | ||
const noop = () => {} | ||
|
||
const customVersioning = { | ||
// storage factory | ||
storage: function () { | ||
let versions = {} | ||
return { | ||
get: (version) => { return versions[version] || null }, | ||
set: (version, store) => { versions[version] = store }, | ||
del: (version) => { delete versions[version] }, | ||
empty: () => { versions = {} } | ||
} | ||
}, | ||
deriveVersion: (req, ctx) => { | ||
return req.headers['accept'] | ||
} | ||
} | ||
|
||
test('A route could support multiple versions (find) / 1', t => { | ||
t.plan(5) | ||
|
||
const findMyWay = FindMyWay({ versioning: customVersioning }) | ||
|
||
findMyWay.on('GET', '/', { version: 'application/vnd.example.api+json;version=2' }, noop) | ||
findMyWay.on('GET', '/', { version: 'application/vnd.example.api+json;version=3' }, noop) | ||
|
||
t.ok(findMyWay.find('GET', '/', 'application/vnd.example.api+json;version=2')) | ||
t.ok(findMyWay.find('GET', '/', 'application/vnd.example.api+json;version=3')) | ||
t.notOk(findMyWay.find('GET', '/', 'application/vnd.example.api+json;version=4')) | ||
t.notOk(findMyWay.find('GET', '/', 'application/vnd.example.api+json;version=5')) | ||
t.notOk(findMyWay.find('GET', '/', 'application/vnd.example.api+json;version=6')) | ||
}) |
File renamed without changes.