Last active
February 8, 2019 08:54
-
-
Save yeyuguo/b63f7b8f87909a7341959ca4074361ce to your computer and use it in GitHub Desktop.
koa 请求参数查看
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const Koa = require('koa') | |
| const Router = require('koa-router'); | |
| const app = new Koa(); | |
| const router = new Router(); | |
| router.get( | |
| '/csrf', | |
| (ctx, next) => { | |
| ctx.body = "test csrf" | |
| } | |
| ) | |
| app.use(router.routes()) | |
| app.use(async (ctx, next) => { | |
| let url = ctx.url | |
| let url_path = ctx.path | |
| // 从上下文的request对象中获取 | |
| let request = ctx.request | |
| let req_query = request.query | |
| let req_querystring = request.querystring | |
| // 从上下文中直接获取 | |
| let ctx_query = ctx.query | |
| let ctx_querystring = ctx.querystring | |
| if (url_path == '/test') { | |
| ctx.body = { | |
| url, | |
| req_query, | |
| req_querystring, | |
| ctx_query, | |
| ctx_querystring | |
| } | |
| } | |
| }) | |
| app.listen(3000, () => { | |
| console.log('[demo] request get is starting at port 3000') | |
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const Koa = require('koa') | |
| const app = new Koa() | |
| app.use( async ( ctx ) => { | |
| let url = ctx.url | |
| let url_path = ctx.path | |
| // 从上下文的request对象中获取 | |
| let request = ctx.request | |
| let req_query = request.query | |
| let req_querystring = request.querystring | |
| // 从上下文中直接获取 | |
| let ctx_query = ctx.query | |
| let ctx_querystring = ctx.querystring | |
| ctx.body = { | |
| url, | |
| req_query, | |
| req_querystring, | |
| ctx_query, | |
| ctx_querystring | |
| } | |
| }) | |
| app.listen(3000, () => { | |
| console.log('[demo] request get is starting at port 3000') | |
| }) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment