ISIL-ESTE / Student-Workflow-Organizer

The Workflow Organizer website helps students to organize their academic workload through features such as a dashboard, timeline, reminders, collaboration tools, resource library, progress tracking, and analytics. It also allows users to share and summarize courses and seek project help.
MIT License
46 stars 21 forks source link

TSOA - Route Versioning #154

Closed bellaabdelouahab closed 2 months ago

bellaabdelouahab commented 10 months ago

In our previous behavior, we used to do something like this:

routes
app.use(
    `/api`,
    routesVersioning()({
        '1.0.0': indexRouter,
    })
);

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

RegisterRoutes(app);

so we will need a new approach for API versioning

muttaqin1 commented 10 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.

muttaqin1 commented 10 months ago

@bellaabdelouahab

bellaabdelouahab commented 10 months ago

@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