koa-mysql(二)

路由

安装依赖

cnpm install koa-router --save

修改index.js

const koa = require('koa');
const router = require('koa-router')();
const app = new koa();

router.get('/',async(ctx,next) => {
    ctx.response.body = "<h1>hello,world</h1>"
})

app.use(router.routes());
app.listen(3000);
console.log(`app start at localhost:3000`);

http://localhost:3000/

koa-mysql(二)

别的页面

const koa = require('koa');
const router = require('koa-router')();
const app = new koa();

router.get('/',async(ctx,next) => {
    ctx.response.body = "<h1>hello,world</h1>"
})
router.get('/hello',async(ctx,next) => {
    ctx.response.body = "this is hello page"
})
router.get('/hello/:name',async(ctx,next) => {
    var name = ctx.params.name;
    ctx.response.body = `<h1>hello,${name}</h1>`
})


app.use(router.routes());
app.listen(3000);
console.log(`app start at localhost:3000`);

http://localhost:3000/hello

koa-mysql(二)

http://localhost:3000/hello/biao

koa-mysql(二)

post

相关推荐