UNPKG

@misterzik/espressojs

Version:

EspressoJS Introducing Espresso.JS, your ultimate Express configuration starting point and boilerplate. With its simplicity and lack of opinionation, EspressoJS offers plug-and-play configurations built on top of Express.

61 lines (54 loc) 1.43 kB
/* * _| _| _| _| _|_|_| * _| _| _|_| _|_| _| _| * _| _| _| _| _| _| _| * _| _| _| _| _| _| * _| _| _| _|_|_| * EspressoJS - Security Middleware */ const helmet = require("helmet"); const rateLimit = require("express-rate-limit"); const helmetConfig = () => { return helmet({ contentSecurityPolicy: { directives: { defaultSrc: ["'self'"], styleSrc: ["'self'", "'unsafe-inline'"], scriptSrc: ["'self'", "'unsafe-inline'"], imgSrc: ["'self'", "data:", "https:"], }, }, crossOriginEmbedderPolicy: false, crossOriginResourcePolicy: { policy: "cross-origin" }, }); }; const rateLimiter = rateLimit({ windowMs: 15 * 60 * 1000, max: 100, message: "Too many requests from this IP, please try again later.", standardHeaders: true, legacyHeaders: false, }); const strictRateLimiter = rateLimit({ windowMs: 15 * 60 * 1000, max: 10, message: "Too many requests from this IP, please try again later.", standardHeaders: true, legacyHeaders: false, }); const apiRateLimiter = rateLimit({ windowMs: 15 * 60 * 1000, max: 200, message: { status: "error", message: "Too many API requests from this IP, please try again later.", }, standardHeaders: true, legacyHeaders: false, }); module.exports = { helmetConfig, rateLimiter, strictRateLimiter, apiRateLimiter, };