1 Star 0 Fork 1

SongZX / node+koa实现mock服务器

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
server.js 883 Bytes
一键复制 编辑 原始数据 按行查看 历史
SongZX 提交于 2021-03-09 13:34 . 更行项目文档
const Koa = require('koa')
const app = new Koa()
const Router = require('koa-router')
const router = new Router()
const bodyParser = require('koa-bodyparser')
app.use(bodyParser())
// 将koa和中间件连起来
app.use(router.routes()).use(router.allowedMethods());
// get请求用户信息
const userInfo = require('./state/userinfo')
app.use(userInfo.routes(), userInfo.allowedMethods())
// post请求数据
const postdata = require('./state/postdata')
app.use(postdata.routes(), postdata.allowedMethods())
// 设置启动端口
let port = 3000;
// http://localhost:3000
app.listen(port, (ctx) => {
console.log('服务启动成功:http://localhost:' + port)
router.get('/', async (ctx, next) => {
ctx.body = `
<h2 style="text-align: center;margin: 10%;">
当你看到此页面时表示服务启动成功
</h2>
`
})
})
1
https://gitee.com/szxio/koa2-demo.git
git@gitee.com:szxio/koa2-demo.git
szxio
koa2-demo
node+koa实现mock服务器
master

搜索帮助