Information
Create routes and middleware using classes and a filepath based routing system like Next.js.
Install
yarn add @snowcrystals/highway express
npm install @snowcrystals/highway express
Documentation
The documentation (API Reference) can be found on our website
Examples
The following examples are written in TypeScript with decorators enabled. The examples do not show the required imports (because the only imports you will need are @snowcrystals/highway components).
For a non-decorator version, use a constructor and move the options to the super function inside the constructor (example below)
class HelloWorldRoute extends Route {
constructor() {
super(options); // <-- Options are the options from the decorator, they are all optional
}
}
Route Example
@ApplyOptions<Route.Options>({
middleware: [[Methods.GET, "log"]]
})
class HelloWorldRoute extends Route {
public [Methods.GET](req: Request, res: Response) {
res.send("Hello World");
}
}
Middleware Example
@ApplyOptions<Middleware.Options>({
name: "log"
})
class LogMiddleware extends Middleware {
public [Methods.GET](req: Request, res: Response, next: NextFunction) {
console.log("Hello world route");
next();
}
}
Author
👤 ijsKoud
- Website: https://ijskoud.dev/
- Email: hi@ijskoud.dev
- Twitter: @ijsKoud
- Github: @ijsKoud
Donate
This will always be open source project, even if I don't receive donations. But there are still people out there that want to donate, so if you do here is the link PayPal or to Ko-Fi. Thanks in advance! I really appriciate it <3
License
Project is licensed under the © MIT License