Releases: Danilqa/node-file-router
v0.8.0
v0.7.0
What's new
Features
Now, node-file-router
supports classes. The main requirement is that it should be the default export.
export default class Resource {
get(req, res, routeParams) {
const { documentId, draftId } = routeParams;
res.end(`Requested document ${documentId} and his draft ${draftId}`);
}
post(req, res, routeParams) {
const { documentId, draftId } = routeParams;
res.end(`Created draft ${draftId} for document ${documentId}`);
}
patch(req, res, routeParams) {
// ...
}
}
Alternatively, you can export a class instance:
class SomeResource {
get(req, res, routeParams) {
// ...
}
}
export default new SomeResource();
v0.6.0
What's new
Features
Added the ability to modify or override a final result in middlewares (#41).
For example, you can now set response headers in Bun inside middlewares:
import type { NextFunction } from 'node-file-router';
export async function useCors(req: Request, next: NextFunction<Response>) {
const res = await next();
res.headers.set('Access-Control-Allow-Methods', 'PUT, POST, OPTIONS, HEAD');
return res;
}
Documentation
- Added information about this update.
- Set the valid links for Edit this page
v0.5.2
What's new
Important Fixes
Added a proper route params processing in the middlewares (#35).
For instance, the following code will now work correctly:
// file: api/users/[id].[post].js
async function useMyMiddleware(req: Request, next: NextFunction, routeParams: Record<string, string>) {
// routeParams now have values here
await next();
}
async function createOrUpdateUser(req: Request, routeParams: RouteParams) {
// As well as here
}
export default [
useMyMiddleware,
createOrUpdateUser,
];
Documentation
v0.5.1
What's new
Important Fixes
Fixed the issue with the TypeScript import declaration (#31).
Documentation
v0.5.0
What's new
Middlewares (#18)
It allows you to write additional logic before and after requests. For instance, it enables tasks such as authentication verification, request logging, error handling, and more. You can apply middleware to the entire application, to specific route handler, or to a group of routes within a folder.
See how it works on the website
v0.4.0
v0.3.1
v0.3.0
What's new
1. Methods in Filenames (#6)
You can now specify a method in filenames, which works with all route types. For example, login.[post].ts
, [id].[patch].ts
, and even [...tags].[get].ts
! For more information, refer to the new section in the documentation. Thanks, @angelhdzmultimedia, for this awesome idea.
2. Ability to use catch-all in the middle of the URL (#7)
Now, the image-proxy/[...operations]/url/[image].ts
is valid.