JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 163
  • Score
    100M100P100Q69412F
  • License MIT

serve express middleware once

Package Exports

  • serve-once

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (serve-once) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

Serve Once License NPM version Dependency Status Build Status Coverage Status

Serve express middleware once.

Install

npm i serve-once

API

const middleware = (options = 'hello') => (req, res) => {
    res.end(JSON.stringify(options));
};

const {request} = require('serve-once')(middleware);

await request('get', '/');
// returns
'hello'

await request.get('/', {
    options: 'any'
});
// returns
'any'

const pullout = require('pullout');
const putMiddleware = () => callbackify(async (req, res) => {
    const body = pullout(req);
    res.end(body);
});

const {request} = require('serve-once')(putMiddleware);
const {body} = await request.put('/', {
    body: [1, 2, 3],
    options: 'any'
});

console.log(JSON.parse(body));
// returns
[1, 2, 3]

License

MIT