Closed bellaabdelouahab closed 4 months ago
This middleware will be initialized before all the routes.
const version_middleware= (req, res, next) => {
const acceptedVersion = req.get('accept-version')
const basePath = '/api'
const routePath = `${basePath}/${acceptedVersion}`
req.url = req.url.replace(basePath, routePath) //Modify the request url to route to the versioned controller.
next();
}
NOTE: This is just my idea. Test this and let me know if this works or not.
@bellaabdelouahab
@muttaqin1 I've already tested it; it changed the url, but the url that controls the request is not changeable. you can only change which function to call
In our previous behavior, we used to do something like this:
but now that we have switched to TSOA, we do not have the option to control what routes get triggered based on api version in the header
so we will need a new approach for API versioning