当前位置:网站首页>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)边栏推荐
- Analysis of blocktoken principle
- The communication mechanism and extension of Supervisor
- Is the public read-only field with immutable structure valid- Does using public readonly fields for immutable structs work?
- The girlfriend said: if you want to understand the three MySQL logs, I will let you heiheihei!
- PHP online confusion encryption tutorial sharing + basically no solution
- ArrayList分析1-循环、扩容、版本
- MySQL variables, stored procedures and functions
- History of deep learning
- A letter to 5000 fans!
- Self examination before school starts
猜你喜欢
![[daily record] - bug encountered in BigDecimal division operation](/img/82/3105586841076b9bb1c57eac221ddf.png)
[daily record] - bug encountered in BigDecimal division operation

C#生成putty格式的ppk文件(支持passphrase)
![[original] PLSQL index sorting optimization](/img/91/dcd0262705a19645f1a87d4cf03bc8.jpg)
[original] PLSQL index sorting optimization

Using C language to realize the exchange between the contents of two arrays (provided that the array is the same size)

MySQL variables, stored procedures and functions

Oracle table creation and management

魔王冷饭||#101 魔王解惑数量多与质量;员工管理;高考志愿填报;游戏架构设计

The communication mechanism and extension of Supervisor

The principle of journal node

Cmu15445 (fall 2019) project 1 - buffer pool details
随机推荐
CSDN常用复杂公式模板记录
P4 learning - p4runtime
Oracle temporary table explanation
Longest valid bracket
Luogu p1144 shortest circuit count
最长的可整合子数组的长度
Oracle-表的创建与管理
Search rotation sort array
Is the public read-only field with immutable structure valid- Does using public readonly fields for immutable structs work?
Wechat official account development (1) introduction to wechat official account
第53章 从业务逻辑实现角度整体性理解程序
CTF tool (1) -- archpr -- including installation / use process
2022-2028 global ultra high purity electrolytic iron powder industry research and trend analysis report
Left join displays the specified value when the left join matching data is null
2022-2028 global ultra high purity electrolytic iron sheet industry research and trend analysis report
HDU 2488 A Knight's Journey(DFS)
2022-2028 global rampant travel industry research and trend analysis report
Detailed analysis of operators i++ and ++i in JS, i++ and ++i
问题解决:如何管理线程私有(thread_local)的指针变量
P4 learning - Basic tunneling
