Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/koajs/koa-safe-jsonp
Safe jsonp plusins for koa.
https://github.com/koajs/koa-safe-jsonp
Last synced: 2 months ago
JSON representation
Safe jsonp plusins for koa.
- Host: GitHub
- URL: https://github.com/koajs/koa-safe-jsonp
- Owner: koajs
- License: mit
- Created: 2014-07-17T15:30:34.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2021-06-27T08:54:11.000Z (over 3 years ago)
- Last Synced: 2024-04-14T13:08:40.555Z (8 months ago)
- Language: JavaScript
- Size: 117 KB
- Stars: 16
- Watchers: 6
- Forks: 6
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: History.md
- License: LICENSE
Awesome Lists containing this project
- awesome-koa - koa-safe-jsonp - Safe jsonp plusins for koa. (Middleware)
- awesome-koa - koa-safe-jsonp - 安全的Koa JSONP插件。 ![](https://img.shields.io/github/stars/koajs/koa-safe-jsonp.svg?style=social&label=Star) ![](https://img.shields.io/npm/dm/koa-safe-jsonp.svg?style=flat-square) (仓库 / 中间件)
README
[koa-safe-jsonp][github-repo]
=======[![NPM version][npm-image]][npm-url]
[![build status][travis-image]][travis-url]
[![Test coverage][codecov-image]][codecov-url]
[![David deps][david-image]][david-url][github-repo]: https://github.com/koajs/koa-safe-jsonp
[npm-image]: https://img.shields.io/npm/v/koa-safe-jsonp.svg?style=flat
[npm-url]: https://npmjs.org/package/koa-safe-jsonp
[travis-image]: https://img.shields.io/travis/koajs/koa-safe-jsonp.svg?style=flat
[travis-url]: https://travis-ci.org/koajs/koa-safe-jsonp
[codecov-image]: https://codecov.io/github/koajs/koa-safe-jsonp/coverage.svg?branch=master
[codecov-url]: https://codecov.io/github/koajs/koa-safe-jsonp?branch=master
[david-image]: https://img.shields.io/david/koajs/koa-safe-jsonp.svg?style=flat
[david-url]: https://david-dm.org/koajs/koa-safe-jsonpSafe jsonp plugins for koa.
## Install
```bash
# npm ..
$ npm i koa-safe-jsonp
# yarn ..
$ yarn add koa-safe-jsonp
```## Usage
```js
const 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:
```bash
$ 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
[MIT](LICENSE)