![Create React App Officially Deprecated Amid React 19 Compatibility Issues](https://cdn.sanity.io/images/cgdhsj6q/production/04fa08cf844d798abc0e1a6391c129363cc7e2ab-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Create React App Officially Deprecated Amid React 19 Compatibility Issues
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.
version-router-express
Advanced tools
npm install --save version-router-express
import:
import {VersionRouter, VersionedRoute} from 'version-router-express';
This module generates Express middleware that enables efficient management of api routes versions. It enables the use of middleware arrays for each version of the route, and flexible version resolving strategies.
VersionedRoute assumes the existence of a 'version' property on the request object. This property can be generated in any way along the route's path. VersionedRoute has a static utility method that can be mounted to extract the version from a header and assign it to req.version.
app.use(VersionedRoute.ExtractVersionFromHeader('App-version'));
Any custom header can be used, as well as any other strategy for assigning a value to request.version
Version matching is done according to semver standards.
const routeVersions = [
new VersionedRoute({
version: '1.0.0',
default: false,
middleware: [
(req: Request, res: Response, next: NextFunction) => {
console.log('route 2 function 1')
next()
},
(req: Request, res: Response, next: NextFunction) => {
console.log('route 2 function 2')
res.send({route: '1'})
},
]
}),
new VersionedRoute({
version: '>=1.2.0 <2.0.0',
default: false,
middleware: [
(req: Request, res: Response, next: NextFunction) => {
console.log('route 2 function 1')
next()
},
(req: Request, res: Response, next: NextFunction) => {
console.log('route 2 function 2')
res.send({route: '2'})
},
]
}),
new VersionedRoute({
version: '2.0.0',
default: true,
middleware: [
(req: Request, res: Response, next: NextFunction) => {
console.log('route 3 function 1')
next()
},
(req: Request, res: Response, next: NextFunction) => {
console.log('route 3 function 2')
res.send({route: '3'})
},
]
})
]
Request version is checked against the versioned route 'version' property according to the semver standard.
If no matches were found, it will resolve to the route defined as default.
app.use('/testRoute', new VersionRouter(routeVersions).routeRequestByVersion)
The router can be configured with a custom error handler for the version matching stage of the
app.use('/testRoute', new VersionRouter(
routeVersions,
{
errorHandler: (req, res, next) => {
// TODO do some error handling stuff
next(new Error('some message'))
}
}).routeRequestByVersion)
Creates a router instance to route requests according to the value of req.version
export declare class VersionRouter
Constructor | Description |
---|---|
constructor(routes, options) | Constructs a new instance of the VersionRouter class |
Property | Modifiers | Type | Description |
---|---|---|---|
errorHandler | (req: RequestWithVersion, res: Response, next: NextFunction) => void | Error handler function for the version matching stage | |
routes | Array<VersionedRoute> | Array of VersionedRoute defining the routing options and versions |
Method | Modifiers | Description |
---|---|---|
ExtractVersionFromHeaders(versionHeader) | static | Middleware for extracting the version from the said request header and assign it to req.version Mount it once BEFORE all versioned routes |
routeRequestByVersion() | Middleware to mount on the route path e.g. app.use('/api/users', UsersRoutes.routeRequestByVersion()) |
Creates a versioned route object that contains middleware and version data
Signature:
export declare class VersionedRoute implements VersionedMiddleware
Implements: VersionedMiddleware
Constructor | Description |
---|---|
constructor(config) | Constructs a new instance of the VersionedRoute class |
Property | Modifiers | Type | Description |
---|---|---|---|
default | boolean | Sets the version as default.VersionRouter will resolve to the default route in when version property is undefined or no matching version was found | |
middleware | Array<RequestHandler> | An array of request handlers to mount on the versioned route | |
version | string | Semver version number |
Method | Modifiers | Description |
---|---|---|
toRouter() | returns a Router instance with the route's middleware mounted |
FAQs
Lightweight api versioning tool for express
The npm package version-router-express receives a total of 0 weekly downloads. As such, version-router-express popularity was classified as not popular.
We found that version-router-express demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.