💫 A file-based routing for Node.js. Works with Bun, pure Node.js, Express.js, and more!
MIT License
Bot releases are visible (Hide)
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;
}
Published by Danilqa 9 months ago
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,
];
Published by Danilqa 9 months ago
Fixed the issue with the TypeScript import declaration (#31).
Published by Danilqa 9 months ago
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
Thanks @EvHaus for the suggestion! #25
Published by Danilqa 11 months ago
Clear Import Cache (#18)
It allows you to re-import updated files during the service runtime.
See how it works on the website
Thank you @coxmi for suggestion! #13
Website
Moved images to the CDN. The page loading speed has increased.
Published by Danilqa about 1 year ago
Improved readme (#9)
Now, it's easier to understand what's going on in the library.
Linter improvement (#8)
Published by Danilqa about 1 year ago
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.