-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add compliled lib files to repository
- Loading branch information
Ehtesham Hasnain
authored and
Ehtesham Hasnain
committed
Sep 30, 2020
1 parent
ccee16f
commit 6e386dd
Showing
6 changed files
with
97 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export { routeBlocker } from "./route-blocker"; | ||
export interface RoutesBlockingMap { | ||
[route: string]: boolean; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.routeBlocker = void 0; | ||
var route_blocker_1 = require("./route-blocker"); | ||
Object.defineProperty(exports, "routeBlocker", { enumerable: true, get: function () { return route_blocker_1.routeBlocker; } }); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { NextFunction, Request, Response } from "express"; | ||
import { RoutesBlockingMap } from "."; | ||
declare class RouteBlocker { | ||
private static instance; | ||
private routesBlockingMap; | ||
constructor(); | ||
get routeBlocks(): RoutesBlockingMap; | ||
middleware(route: string): (req: Request, res: Response, next: NextFunction) => Response<any> | undefined; | ||
disableRoute(route: string): void; | ||
enableRoute(route: string): void; | ||
clearBlockings(): void; | ||
private isRouteBlocked; | ||
private routeBlockingExists; | ||
} | ||
export declare const routeBlocker: RouteBlocker; | ||
export {}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.routeBlocker = void 0; | ||
const utils_1 = require("./utils"); | ||
class RouteBlocker { | ||
constructor() { | ||
this.routesBlockingMap = {}; | ||
if (RouteBlocker.instance instanceof RouteBlocker) { | ||
return RouteBlocker.instance; | ||
} | ||
RouteBlocker.instance = this; | ||
} | ||
get routeBlocks() { | ||
return this.routesBlockingMap; | ||
} | ||
middleware(route) { | ||
return (req, res, next) => { | ||
if (this.isRouteBlocked(route)) { | ||
return res.status(503).send(`Route - ${route} currently unavailable`); | ||
} | ||
next(); | ||
}; | ||
} | ||
disableRoute(route) { | ||
if (utils_1.isValidString(route)) { | ||
this.routesBlockingMap[route] = true; | ||
console.warn(`Route "${route}": disabled ⛔️`); | ||
} | ||
else { | ||
console.error("Invalid route key 🤡!"); | ||
} | ||
} | ||
enableRoute(route) { | ||
if (utils_1.isValidString(route)) { | ||
console.info(`Route "${route}": enabled ✅`); | ||
this.routesBlockingMap[route] = false; | ||
} | ||
else { | ||
console.error("Invalid route key 🤡!"); | ||
} | ||
} | ||
clearBlockings() { | ||
this.routesBlockingMap = {}; | ||
} | ||
isRouteBlocked(route) { | ||
if (!this.routeBlockingExists(route)) { | ||
return false; | ||
} | ||
return this.routesBlockingMap[route] === true; | ||
} | ||
routeBlockingExists(route) { | ||
if (route in this.routesBlockingMap) { | ||
return true; | ||
} | ||
return false; | ||
} | ||
} | ||
exports.routeBlocker = new RouteBlocker(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export declare function isValidString(stringVariable: string): boolean; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.isValidString = void 0; | ||
function isValidString(stringVariable) { | ||
if (stringVariable && !containsSpaces(stringVariable)) { | ||
return true; | ||
} | ||
return false; | ||
} | ||
exports.isValidString = isValidString; | ||
function containsSpaces(stringVariable) { | ||
return stringVariable.indexOf(" ") !== -1; | ||
} |