express-middleware-fetch
v1.0.11
Published
Fetch routes from other express middlewares
Downloads
86
Maintainers
Readme
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": "[email protected]",
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