import { Route, RequestHandler } from "simple-route";
const auth: RequestHandler = (req, res, next) => {
console.log("Auth middleware");
if (next) return next()
}
const token: RequestHandler = (req, res, next) => {
console.log("Token middleware");
if (next) return next()
}
const route = Route.create({
path: "/user",
method: "GET",
middlewares: [auth],
func(req, res) {
res.send("This is user page")
},
childs: [
{
path: "/:userid",
method: "GET",
middlewares: [token],
func(req, res){
res.send(`userid is ${req.params.userid}`);
}
}
]
})
import express, { Application } from "express";
const app: Application = express();
route.use(app, "/api/v1");
const port = 3000;
app.listen(port, () => {
console.log(`app started on port ${port}`)
});