New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support for multiple versions #39
Comments
This would be a good addition, as long as it does not slow things down. My worry is if we need to add a check for this in all the other nodes. |
I'll check if I can implement it without compromising the performances. |
@delvedor thanks! |
@hekike maybe use store is a good choice!
|
@i5ting it could be a solution, but the problem is that we should use semver, which as far as I know uses regular expressions massively. To lower the friction that this change will introduce we should find a way (lol) to store the different handlers in the node and define which one use inside the I'm working on this. |
@hekike I'm wondering if we want to support a semver range in the declaration: router.on('GET', '/', '>=2.5.0', (req, res, params) => {
res.end('{"message":"hello world 1"}')
}) |
How about that routes have a fix version number like For example: router.on('GET', '/', '1.1.0', (req, res, params) => {
res.end('hello world 1.1.0')
})
router.on('GET', '/', '1.2.0', (req, res, params) => {
res.end('hello world 1.2.0')
})
// 'accept-version': '^1.1.0' => 'hello world 1.2.0' Example for finding the greatest version from var semver = require('semver');
...
var reqVersion = req.version(); // accept-version header
var maxVersion;
var maxVersionIndex;
candidates.forEach(function forEach(candidate, idx) {
var version = semver.maxSatisfying(
candidate.version,
reqVersion
);
if (version) {
// Is this version greater?
if (!maxVersion || semver.gt(version, maxVersion)) {
maxVersion = version;
maxVersionIndex = idx;
}
}
});
// No version found
if (_.isUndefined(maxVersionIndex)) {
next(
new InvalidVersionError(
'%s is not supported by %s %s',
req.version() || '?',
req.method,
req.path()
)
);
return;
}
candidates[maxVersionIndex].handler(req, res, next); |
I thought about this and there is not an easy way to insert it without compromising the performances and the structure of the tree. The easiest solution without compromising the performances is to build a wrapper around If you have some better solution, please make a proposal! :) |
Okay, thanks for putting effort into it. For now, we will handle route versioning with a middleware that sits after |
Awesome. Closing this then. |
Have you ever considered to add version support to
find-my-way
?If I understand correctly it could be a new child node in a Radix Tree below the path node.
Something like this:
Lookup could happen by
Accept-Version
header with finding the biggest version that satisfies viasemver
.The text was updated successfully, but these errors were encountered: