在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称:koajs/koa-safe-jsonp开源软件地址:https://github.com/koajs/koa-safe-jsonp开源编程语言:JavaScript 100.0%开源软件介绍:koa-safe-jsonpSafe jsonp plugins for koa. Install# npm ..
$ npm i koa-safe-jsonp
# yarn ..
$ yarn add koa-safe-jsonp Usageconst jsonp = require('koa-safe-jsonp');
const Koa = require('Koa');
const app = new Koa();
jsonp(app, {
callback: '_callback', // default is 'callback'
limit: 50, // max callback name string length, default is 512
});
app.use(function (ctx) {
ctx.jsonp = {foo: "bar"};
});
app.listen(1984); curl test it: $ curl 'http://127.0.0.1:1984/foo.json?_callback=fn' -v
* About to connect() to 127.0.0.1 port 1984 (#0)
* Trying 127.0.0.1...
* Adding handle: conn: 0x7fca3c004000
* Adding handle: send: 0
* Adding handle: recv: 0
* Curl_addHandleToPipeline: length: 1
* - Conn 0 (0x7fca3c004000) send_pipe: 1, recv_pipe: 0
* Connected to 127.0.0.1 (127.0.0.1) port 1984 (#0)
> GET /foo.json?_callback=fn HTTP/1.1
> User-Agent: curl/7.30.0
> Host: 127.0.0.1:1984
> Accept: */*
>
< HTTP/1.1 200 OK
< X-Powered-By: koa
< X-Content-Type-Options: nosniff
< Content-Type: application/javascript
< Content-Length: 51
< Date: Thu, 17 Jul 2014 15:29:05 GMT
< Connection: keep-alive
<
* Connection #0 to host 127.0.0.1 left intact
/**/ typeof fn === 'function' && fn({"foo":"bar"}); License |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论