Create routes and middleware using classes and a filepath based routing system like Next.js.
yarn add @snowcrystals/highway express
npm install @snowcrystals/highway express
The documentation (API Reference) can be found on our website
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
}
}
@ApplyOptions<Route.Options>({
middleware: [[Methods.GET, "log"]]
})
class HelloWorldRoute extends Route {
public [Methods.GET](req: Request, res: Response) {
res.send("Hello World");
}
}
@ApplyOptions<Middleware.Options>({
name: "log"
})
class LogMiddleware extends Middleware {
public [Methods.GET](req: Request, res: Response, next: NextFunction) {
console.log("Hello world route");
next();
}
}
👤 ijsKoud
- Website: https://ijskoud.dev/
- Email: hi@ijskoud.dev
- Twitter: @ijsKoud
- Github: @ijsKoud
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
Project is licensed under the © MIT License