-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
LIME-1343 - Implementing Overload Protection/Adding Vital signs logging
Signed-off-by: ElliotMurphyGDS <[email protected]>
- Loading branch information
1 parent
7ba423e
commit 36edc25
Showing
5 changed files
with
133 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
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
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
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,34 @@ | ||
const logger = require("hmpo-logger").get(); | ||
const router = require("express/lib/router"); | ||
const http = require('http') | ||
const protect = require("overload-protection")("http", protectConfig);//is a reference to app here possible? | ||
|
||
const protectConfig = { | ||
production: process.env.NODE_ENV === 'production', // if production is false, detailed error messages are exposed to the client | ||
clientRetrySecs: 1, // Retry-After header, in seconds (0 to disable) [default 1] | ||
sampleInterval: 5, // sample rate, milliseconds [default 5] | ||
maxEventLoopDelay: 400, // maximum detected delay between event loop ticks [default 42] | ||
maxHeapUsedBytes: 0, // maximum heap used threshold (0 to disable) [default 0] | ||
maxRssBytes: 0, // maximum rss size threshold (0 to disable) [default 0] | ||
errorPropagationMode: false, // dictate behavior: take over the response | ||
// or propagate an error to the framework [default false] | ||
logging: "error", // set to string for log level or function to pass data to | ||
logStatsOnReq: false // set to true to log stats on every requests | ||
}; | ||
|
||
module.exports = function (req, res, next) { | ||
//how do I set app.use in here, If we set to app in app-setup, this will work but not for all requests | ||
//If I set | ||
try { | ||
http.createServer(function (req, res) { | ||
if (protect(req, res) === true) { | ||
router.use(protect); | ||
logger.info("Overload protection enabled"); | ||
} | ||
}) | ||
|
||
next(); | ||
} catch (error) { | ||
return next(error); | ||
} | ||
}; |
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