@abnerlin/express-routes-loader 中文文档教程

发布于 7年前 浏览 21 项目主页 更新于 3年前

Express Routes Loader

Load all routes in directory.

Installation

npm install @abnerlin/express-routes-loader

Usage

const app = express();
const expressRouteLoader = require('@abnerlin/express-routes-loader')(app);

...

Load all routes in direcotry

expressRouteLoader.dir(path.join(__dirname, 'routes')); // which 'routes' is directory path.

Load routes with specify file

expressRouteLoader.file(path.join(__dirname, 'routes', 'auth')); // which 'routes/auth' is file path.

Export url path

const express = require('express');
const router = express.Router();

router.post('/login', function(req, res) {
        ...
});

router.root = '/auth';  // this is url path which must export.

module.exports = router;

Express Routes Loader

Load all routes in directory.

Installation

npm install @abnerlin/express-routes-loader

Usage

const app = express();
const expressRouteLoader = require('@abnerlin/express-routes-loader')(app);

...

Load all routes in direcotry

expressRouteLoader.dir(path.join(__dirname, 'routes')); // which 'routes' is directory path.

Load routes with specify file

expressRouteLoader.file(path.join(__dirname, 'routes', 'auth')); // which 'routes/auth' is file path.

Export url path

const express = require('express');
const router = express.Router();

router.post('/login', function(req, res) {
        ...
});

router.root = '/auth';  // this is url path which must export.

module.exports = router;
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文