This package is no longer maintained.
JSONP is required only for older browsers that don't support requests from third party domains. For modern browsers you can use fetch() and CORS instead.
Contains both a client (bower) and server (npm) module
Emulate fetch's interface, but use JSONP under the hood
bower install -S n-jsonp
import jsonpFetch from 'n-jsonp';
const opts = {
timeout: 1000
};
jsonpFetch('http://other.domain.com/foo', opts)
.then(data => {
...
});
Where opts
can take
{number} [timeout=2000]
Express middleware, to work with the client module
npm install -S @financial-times/n-jsonp
const app = require('express');
const jsonpFetch = require('@financial-times/n-jsonp').default
app = express();
app.use(jsonpMiddleware);
app.get('/', (req, res) => {
res.jsonp('a response');
});
app.get('/error', (req, res) => {
res.status(500)
.jsonp('uh-oh');
});
Requires
$ make install
Requires Firefox
$ make test