@prizemates/http-firewall
Version:
HTTP Firewall based on Spring Security HttpFirewall
26 lines • 1.03 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const express_1 = __importDefault(require("express"));
const index_1 = require("../index");
const app = (0, express_1.default)();
const port = 5428;
// This must be added first, before adding any routes
app.use((0, index_1.httpFirewall)(firewallOptions()));
app.get('/', (req, res) => {
res.send('Http Firewall Demo running');
});
app.listen(port, () => {
console.log(`⚡️[server]: Server is running at http://localhost:${port}`);
});
function firewallOptions() {
// Allows traffic from specific hosts only
const allowedHostnamesPredicate = index_1.Predicate.of((h) => h === 'www.example.com').or(index_1.Predicate.of((h) => h === 'localhost'));
return {
allowedHostnames: allowedHostnamesPredicate,
allowedHttpMethods: ['POST', 'GET'],
};
}
//# sourceMappingURL=demo.js.map