Skip to content
This repository has been archived by the owner on May 20, 2020. It is now read-only.
/ n-jsonp Public archive

❌Deprecated: This package is no longer maintained, consider using fetch() and CORS instead

Notifications You must be signed in to change notification settings

Financial-Times/n-jsonp

Repository files navigation

Next JSONP

Deprecated

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

Client

Emulate fetch's interface, but use JSONP under the hood

Install

bower install -S n-jsonp

Usage

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]

Server

Express middleware, to work with the client module

Install

npm install -S @financial-times/n-jsonp

Usage

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');
});

Development

Setup

Requires

$ make install

Testing

Requires Firefox

$ make test