node-file-router

💫 A file-based routing for Node.js. Works with Bun, pure Node.js, Express.js, and more!

MIT License

Downloads
730
Stars
151
Committers
2

Bot releases are hidden (Show)

node-file-router - v0.6.0 Latest Release

Published by Danilqa 8 months ago

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

node-file-router - v0.5.2

Published by Danilqa 9 months ago

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

Added information about this update.

node-file-router - v0.5.1

Published by Danilqa 9 months ago

What's new

Important Fixes

Fixed the issue with the TypeScript import declaration (#31).

Documentation

  1. Added examples of using Bun with TypeScript.
  2. Added a section about the usage of shared state.
node-file-router - v0.5.0

Published by Danilqa 9 months ago

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

Thanks @EvHaus for the suggestion! #25

node-file-router - v0.4.0

Published by Danilqa 11 months ago

What's new

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.

node-file-router - v0.3.1

Published by Danilqa about 1 year ago

What's new

Improved readme (#9)
Now, it's easier to understand what's going on in the library.

Development

Linter improvement (#8)

  • No more weird not related warnings in interfaces about not used variables.
  • Added linter for commit messages: conventional commits.
node-file-router - v0.3.0

Published by Danilqa about 1 year ago

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.