express-routes-setting
v1.0.2
Published
Batch set route methods(GET | POST | PUT | DELETE | ...) for express routing.
Downloads
12
Readme
express-routes-setting
集中设置express路由。
安装依赖包
npm install --save express-routes-setting
使用方法:
// 完整例子,查看 example 目录。 下面是 example 中 index.ts的示例代码:
import * as express from "express";
import { setExpressRouting } from "express-routes-setting";
var app = express();
async function index(req: express.Request, res: express.Response, next?: express.NextFunction) {
console.log(req.method, " /");
res.send("Hello World");
}
async function show(req: express.Request, res: express.Response) {
console.log(req.method, " /show");
res.send("ok");
}
setExpressRouting(app, [
{ path: "/", method: "get", func: index },
{ path: "/show", method: "get", func: show }
]);
app.use("/home", require("./controller/home"));
app.listen(3000);