Coder Social home page Coder Social logo

koa-safe-jsonp's Introduction

koa-safe-jsonp

NPM version build status Test coverage David deps

Safe jsonp plusins for koa.

Install

$ npm install koa-safe-jsonp

Usage

var jsonp = require('koa-safe-jsonp');
var koa = require('koa');

var app = koa();
jsonp(app, {
  callback: '_callback', // default is 'callback'
  limit: 50, // max callback name string length, default is 512
});

app.use(function* () {
  this.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

MIT

koa-safe-jsonp's People

Contributors

fengmk2 avatar dead-horse avatar coolme200 avatar yongbo000 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.