当前位置:网站首页>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)边栏推荐
- Packing and unpacking of C #
- 蒹葭苍苍,白露为霜。
- 双位置继电器DLS-5/2 DC220V
- [network packet loss and network delay? This artifact can help you deal with everything!]
- Kongyiji's first question: how much do you know about service communication?
- K210 site helmet
- Service
- Web compatibility testing of software testing
- [learning notes] structure
- 冲击继电器ZC-23/DC220V
猜你喜欢

Vnctf 2022 cm CM1 re reproduction

Install redis database and download redis Desktop Manager in win11

Orb-slam2 source code learning (II) map initialization

【学习笔记】构造

Training discipline principle of robot programming

友盟(软件异常实时监听的好帮手:Crash)接入教程(有点基础的小白最易学的教程)

ORB-SLAM2源码学习(二)地图初始化

Double position relay dls-5/2 dc220v

用recyclerReview展示Banner,很简单

酒旅板块复苏,亚朵继续上市梦,距离“新住宿经济第一股“还有多远?
随机推荐
Tcp/ip protocol stack, about TCP_ RST | TCP_ ACK correct attitude
Windows环境下安装MongoDB数据库
The longest selling mobile phone in China has been selling well since its launch, crushing iphone12
Join table query select generation
Green, green the reed. dew and frost gleam.
Vnctf 2022 cm CM1 re reproduction
(learning power + thinking power) x action power, summary of flywheel effect on the growth of technicians
Vnctf 2022 cm CM1 re reproduction
孔乙己第一问之服务通信知多少?
Dls-42/6-4 dc110v double position relay
Detailed analysis of operators i++ and ++i in JS, i++ and ++i
Web compatibility testing of software testing
Two position relay st2-2l/ac220v
StrictMode带来的思考-StrictMode原理(5)
Document service design
[original] PLSQL index sorting optimization
2021电赛F题openmv和K210调用openmv api巡线,完全开源。
探索互联网时代STEAM教育创新之路
Get to know the drawing component of flutter - custompaint
The quantity and quality of the devil's cold rice 101; Employee management; College entrance examination voluntary filling; Game architecture design
