当前位置:网站首页>Koa koa-combine-routers 分路由管理
Koa koa-combine-routers 分路由管理
2022-07-01 00:37:00 【前端猫】
安装:npm install koa koa-router koa-body @koa/cors koa-json -S
npm install koa-combine-routers -S // 管理路由
koa-combine-routers - npm // 查看源代码
第一步:初始化package.js npm init -y
第二步:npm install koa koa-router koa-body @koa/cors koa-json -S
npm install koa-combine-routers -S // 管理路由
第三步:目录
在api的a.js
function a (ctx){
ctx.body = {
"messgae":"a"
}
}
module.exports = {
a
}在api的b.js
function a (ctx){
ctx.body = {
"messgae":"b"
}
}
module.exports = {
b
}
routes文件的aRouter.js
const KoaRouter = require('koa-router')
const a = require("../api/a.js")
const router = new KoaRouter()
router.get('/a',a)
module.exports = router
routes文件的bRouter.js
const KoaRouter = require('koa-router')
const b = require("../api/b")
const router = new KoaRouter()
router.get('/b',b)
module.exports = router合并路由
const combineRoutes = require('koa-combine-routers')
const aRouters = require("./aRouter")
const bRouters = require("./bRouter")
module.exports = combineRoutes (
aRouters,
bRouters
)
src文件下的index.js
// 入口文件
const koa = require('koa')
const app = new koa()
const router = require('./routes/routes')
app.use(router())
app.listen(3000)边栏推荐
- CMU15445 (Fall 2019) 之 Project#1 - Buffer Pool 详解
- Error 2059 when Navicat connects to MySQL
- Oracle临时表详解
- Double linked list: initialize insert delete traversal
- Host FL Studio fruit music production daw20.9
- [DaVinci developer topic] -37- detail IRV: introduction to inter runnable variable + configuration
- What should I do without 50W bride price
- Get screen height
- Tibetan poem PTA
- 2022-2028 global retro glass industry research and trend analysis report
猜你喜欢

20220215-ctf-misc-buuctf-ningen--binwalk analysis --dd command separation --archpr brute force cracking

剑指 Offer 18. 删除链表的节点

Can JDBC based on openjdk connect to MySQL?

2022-2028 global retro glass industry research and trend analysis report

Stack frame

Analysis of blocktoken principle

Deployment of mini version message queue based on redis6.0

Unit test concept and purpose

2022-2028 global ultra high purity electrolytic iron powder industry research and trend analysis report

20220216 misc buuctf another world WinHex, ASCII conversion flag zip file extraction and repair if you give me three days of brightness zip to rar, Morse code waveform conversion mysterious tornado br
随机推荐
Cmu15445 (fall 2019) project 1 - buffer pool details
Detailed analysis of operators i++ and ++i in JS, i++ and ++i
2022-2028 global weight loss ginger tea industry research and trend analysis report
Date类的实现
2022-2028 global mobile scanning radiology room industry survey and trend analysis report
[2023 MediaTek approved the test questions in advance] ~ questions and reference answers
Error msb8031: building an MFC project for a non Unicode character set is deprecated
[original] PLSQL index sorting optimization
CSDN常用复杂公式模板记录
Analysis of blocktoken principle
Some views on libco
Redis based distributed lock
PyTorch安装并使用gpu加速
Luogu p1168 median
CentOS installation starts redis
CTF tool (1) -- archpr -- including installation / use process
A proper job is a good job
C # Generate PPK files in Putty format (passthrough support)
Wechat official account development (1) introduction to wechat official account
C # generates PPK files in putty format (supports passphrase)
