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

Latest commit

 

History

History
73 lines (44 loc) · 1.16 KB

README.md

File metadata and controls

73 lines (44 loc) · 1.16 KB

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