Skip to content

A middleware for expressjs to block or unblock a route

License

Notifications You must be signed in to change notification settings

ehasnain/route-blocker

Folders and files

NameName
Last commit message
Last commit date

Latest commit

0a486cf · Oct 24, 2020

History

99 Commits
Oct 24, 2020
Oct 3, 2020
Oct 6, 2020
Oct 4, 2020
Oct 4, 2020
Sep 30, 2020
Oct 3, 2020
Sep 28, 2020
Sep 27, 2020
Oct 4, 2020
Oct 24, 2020
Oct 4, 2020
Oct 24, 2020
Oct 3, 2020
Oct 3, 2020

Repository files navigation

A middleware for expressjs to block or unblock a route

Install

Using npm

npm install route-blocker

Using yarn

yarn add route-blocker

Usage

In server.ts (or the file where app and routes are defined)

import { routeBlocker } from "route-blocker";

const BASE_ROUTE = "api/some-base-route";
export const subRouteToBlock = "some-sub-route";
const myRoute = `${BASE_ROUTE}/${subRouteToBlock}`;

app.use(myRoute, routeBlocker.middleware(subRouteToBlock));
app.get(myRoute, myRouteFunction);

In the file where the route blocking should be enabled/disabled

import { routeBlocker } from "route-blocker";
import { subRouteToBlock } from "src/server.ts";

routeBlocker.disableRoute(subRouteToBlock); // disable route

// do something

routeBlocker.enableRoute(subRouteToBlock); // enable route

To remove all route blockings

routeBlocker.clearBlockings();

Note

See the source for more details

package bundle size express release pull request

License

route-blocker is MIT licensed.