当前位置:网站首页>Koa koa combine routes sub route management
Koa koa combine routes sub route management
2022-07-01 01:20:00 【Front end cat】
install :npm install koa koa-router koa-body @koa/cors koa-json -S
npm install koa-combine-routers -S // Manage routes
koa-combine-routers - npm // View the source code
First step : initialization package.js npm init -y
The second step :npm install koa koa-router koa-body @koa/cors koa-json -S
npm install koa-combine-routers -S // Manage routes
The third step : Catalog
stay api Of a.js
function a (ctx){
ctx.body = {
"messgae":"a"
}
}
module.exports = {
a
}stay api Of b.js
function a (ctx){
ctx.body = {
"messgae":"b"
}
}
module.exports = {
b
}
routes Of documents 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 Of documents bRouter.js
const KoaRouter = require('koa-router')
const b = require("../api/b")
const router = new KoaRouter()
router.get('/b',b)
module.exports = routerMerge routes
const combineRoutes = require('koa-combine-routers')
const aRouters = require("./aRouter")
const bRouters = require("./bRouter")
module.exports = combineRoutes (
aRouters,
bRouters
)
src Under the document index.js
// Entrance file
const koa = require('koa')
const app = new koa()
const router = require('./routes/routes')
app.use(router())
app.listen(3000)边栏推荐
- 孔乙己第一问之服务通信知多少?
- High quality pump SolidWorks model material recommended, not to be missed
- 2021电赛F题openmv和K210调用openmv api巡线,完全开源。
- 软硬件基础知识学习--小日记(1)
- 蒹葭苍苍,白露为霜。
- New content violation degree determination scana bad information monitoring capability update issue 5
- Poor students can also play raspberry pie
- 【学习笔记】构造
- Get to know the drawing component of flutter - custompaint
- Locking relay ydb-100, 100V
猜你喜欢

PHP online confusion encryption tutorial sharing + basically no solution

软件开发完整流程

Exploring the road of steam education innovation in the Internet Era

DLS-42/6-4 DC110V双位置继电器

技术人进阶画业务大图,手把手教学来了

Dx-11q signal relay

【网络丢包,网络延迟?这款神器帮你搞定所有!】

The quantity and quality of the devil's cold rice 101; Employee management; College entrance examination voluntary filling; Game architecture design

K210 site helmet

Vnctf 2022 cm CM1 re reproduction
随机推荐
The quantity and quality of the devil's cold rice 101; Employee management; College entrance examination voluntary filling; Game architecture design
JS方法大全的一个小文档
06. on several ways of redis persistence
Docker deployment MySQL 8
Implementation of date class
06.论Redis持久化的几种方式
使用StrictMode-StrictMode原理(1)
Dls-20 double position relay 220VDC
mustache语法
Tcp/ip protocol stack, about TCP_ RST | TCP_ ACK correct attitude
Golang treasure house recommendation
Some views on libco
Exercises on recursion in C language
Inspire students' diversified thinking with steam Education
Practical shell knowledge
Listview in flutter application development
集群与LVS介绍及原理解析
What is product thinking
Q弹松软的大号吐司,带来更舒服的睡眠
关于Unity一般的输入操作方式
