概述 最近学习利用 koa搭建API接口 ,小有所得,现在记录下来,供以后开发时参考,相信对其他人也有用。 就目前我所知道的而言,API有2种,一种是 jsonp 这种API,前端通过ajax来进行跨域请求获得数据;另一种是 restful API ,前端通过fetch或者axios进行cors请求
npm install koa-response-jsonp --save Usage constKoa=require('koa'); constapp=newKoa(); constjsonp=require('koa-response-jsonp'); jsonp(app); app.use(asyncctx=>{ ctx.jsonp({ success:true }); }); app.listen(3000); then you requesthttp://localhost:3000?callback=fnwill response:...
$ npm install koa-jsonp Exampleconst db = require('nano')('http://localhost:5984/my_db') const stringify = require('json-array-stream') const jsonp = require('koa-jsonp') app.use(jsonp()) app.use(mount('/users', function *() { this.type = 'json' this.body = db.view('...
const Koa = require('koa'); const app = new Koa(); const jsonp = require('koa-response-jsonp'); jsonp(app); app.use(async ctx => { ctx.jsonp({ success: true }); }); app.listen(3000); then you request http://localhost:3000?callback=fn will response: fn({"success":true...
9. JSONP实现 - 9.1 原生koa2实现JSONP 9. JSONP实现 - 9.2 koa-jsonp中间件 10. 测试 10. 测试 - 10.1 单元测试 11. debug 11. debug - 11.1 开发debug 12. 项目框架搭建 12. 项目框架搭建 - 12.1 快速启动 12. 项目框架搭建 - 12.2 框架设计 12. 项目框架搭建 - 12.3 分层操作 12. 项目框架...
Pull requests1 Actions Projects Wiki Security Insights More master BranchesTags koa-safe-jsonp/.npmrc Go to file Copy path Cannot retrieve contributors at this time 1 lines (1 sloc)19 Bytes RawBlame package-lock=false Copy lines Copy permalink...
Helper to create more safe jsonp response body for koa and other web framework. - node-modules/jsonp-body
koa jsonp middleware. Contribute to keenwon/koa-response-jsonp development by creating an account on GitHub.