Skip to content

R1ZEN/fastify-jsonp

Repository files navigation

@pbe/fastify-jsonp

checks js-standard-style npm npm bundle size

A plugin for Fastify that adds support for jsonp response.

Installation

npm i @pbe/fastify-jsonp

or

yarn add @pbe/fastify-jsonp

Example

const fastify = require('fastify')()

fastify.register(require('@pbe/fastify-jsonp'))

fastify.get('/', (req, reply) => {
  reply.jsonp({ hello: 'world' });
});

fastify.listen({ port: 3000 });

Terminal:

$ curl "http://localhost:3000/?callback=myCallback"
$ /**/ typeof myCallback === 'function' && myCallback({"hello":"world"});

License

MIT License