express-middleware-fetch
TypeScript icon, indicating that this package has built-in type declarations

1.0.11 • Public • Published

express-middleware-fetch

Fetch routes from other express middlewares

This creates a fetch function, partially compatible with browser fetch, which can be used to fetch routes from the same express server (e.g. routes generated by other middlewares)

Available function

expressMiddlewareFetch(req:express.Request):((url:string|URL,requestInit?:RequestInit)=>Promise<Response>)&{req:express.Request}

Call this function with an express.Request object to create a fetch function for the same express server as that express.Request object.

The 2nd argument is the same as what is usually passed into fetch.

The express.Request object can later be changed on the returned fetch function.

Example

import * as express from 'express';
import expressMiddlewareFetch from 'express-middleware-fetch';

let req:express.Request;
let req2:express.Request;

let fetcher=expressMiddlewareFetch(req);
fetcher('https://localhost/mypath');
fetcher.req=req2;
fetcher('https://localhost/mypath2');

Building instructions

Delete the line "packageManager": "yarn@4.1.1", from package.json. Delete the line yarnPath: .yarn/releases/yarn-4.1.1.cjs from .yarnrc.yml.

npm i -g yarn
yarn set version 4.1.1
yarn --immutable
yarn build

Package Sidebar

Install

npm i express-middleware-fetch

Weekly Downloads

0

Version

1.0.11

License

NPOSL-3.0

Unpacked Size

11.2 kB

Total Files

5

Last publish

Collaborators

  • customautosys