This file contains hidden or 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
| const express = require('express'); | |
| const bodyParser = require('body-parser'); | |
| const helmet = require('helmet'); | |
| const csp = require('helmet-csp'); | |
| let app = express(); | |
| // Implementing basic security defaults using helmet | |
| app.use(helmet()); | |
| // CSP Options |
This file contains hidden or 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
| const express = require('express'); | |
| const bodyParser = require('body-parser'); | |
| const helmet = require('helmet'); | |
| const csp = require('helmet-csp'); | |
| const cors = require('cors'); | |
| let app = express(); | |
| // Implementing basic security defaults using helmet | |
| app.use(helmet()); |
This file contains hidden or 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
| const express = require('express'); | |
| const bodyParser = require('body-parser'); | |
| const helmet = require('helmet'); | |
| const csp = require('helmet-csp'); | |
| const cors = require('cors'); | |
| const rateLimit = require("express-rate-limit"); | |
| let app = express(); | |
| // Implementing basic security defaults using helmet |
This file contains hidden or 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
| const myFirstMiddleware = function(req, res, next) { | |
| someHTTPRequestLibraryOrPUBSUBLibrary.postOrRequest('https://myexternalloggingserver.com/log', {body: req.path}) | |
| .then((data)=>{ | |
| console.log('Sent to logging server', data); | |
| }, (err) =>{ | |
| console.log('Error Occured, log err to local file', err); | |
| }) | |
| next(); | |
| }; |
This file contains hidden or 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
| const myFirstMiddleware = function(req, res, next) { | |
| // Http request to server https://myexternalloggingserver.com/log | |
| someHTTPRequestLibrary.post('https://myexternalloggingserver.com/log', {body: req.path}) | |
| .then((data)=>{ | |
| next(); | |
| }, (err) =>{ | |
| res.status(500).send('Failed'); | |
| }); | |
| }; |
This file contains hidden or 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
| app.post("/someUrl", function(req, res) { | |
| // Content-Type => "application/json" (Header Content-Type in request) | |
| let getContent = req.header('content-type'); | |
| if (getContent !== 'application/json') { | |
| res.status(406).send("Not Acceptable"); | |
| } | |
| // Raw buffer capture in request body (will be covered later) | |
| const contentBody = JSON.parse(req.body.toString('utf8')); | |
| res.send(200).send({result:"Success", content: contentBody}); | |
| }); |
This file contains hidden or 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
| app.post("/someUrl", function(req, res) { | |
| let isFresh = req.fresh; | |
| if (!isFresh) { | |
| res.status(403).send("Forbidden"); | |
| } | |
| const contentBody = JSON.parse(req.body.toString('utf8')); | |
| res.send(200).send({result:"Success", content: contentBody}); | |
| }); |
This file contains hidden or 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
| app.post("/someUrl", function(req, res) { | |
| let hostname = req.hostname; | |
| if (hostname !== "xxx") { | |
| res.status(403).send("Forbidden"); | |
| } | |
| const contentBody = JSON.parse(req.body.toString('utf8')); | |
| res.send(200).send({result:"Success", content: contentBody}); | |
| }); |
This file contains hidden or 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
| app.post("/someUrl", function(req, res) { | |
| let whitelistIPAddress = req.ip; | |
| if (whitelistIPAddress !== "192.168.0.4") { | |
| res.status(403).send("Forbidden"); | |
| } | |
| const contentBody = JSON.parse(req.body.toString('utf8')); | |
| res.send(200).send({result:"Success", content: contentBody}); | |
| }); |