constructor( private readonly configService: ConfigService, private readonly logger: MyLoggerService, ) { this.helmet = helmet(); }
// should render on <head> helmetHeadComponents() { const keys = Object.keys(this.props.helmet) .filter(el => el !== 'htmlAttributes') .map(el => this.props.helmet[el].toComponent()) .filter( el => el.length > 0 || !(Object.keys(el).length === 0 && el.constructor === Object) ); return keys.length ? keys : []; }
// should render on <html> helmetHtmlAttrComponents() { return this.props.helmet.htmlAttributes.toComponent(); }
const server = express(); server.use(helmet());
app.use(bodyparser.json()) app.use(cors()) app.use(helmet()) app.use((err, req, res, next) => { reject(new Error('Something went wrong!, err:' + err))
render() { return ( <html> <head> {this.props.helmet.title.toComponent()} <meta name="viewport" content="width=device-width, initial-scale=1.0" /> {this.props.helmet.meta.toComponent()} <link rel="stylesheet" href="/public/core.min.css" /> <link rel="stylesheet" href="/public/pages/main.min.css" /> <link rel="shortcut icon" href="/public/media/favicon.ico" /> {this.props.helmet.link.toComponent()} </head> <body> <div id="app-mount" dangerouslySetInnerHTML={{ __html: this.props.markup }} /> <script id="app-state" dangerouslySetInnerHTML={{ __html: this.props.state }} /> <script src="/public/core.min.js"></script> <script src="/public/pages/main.min.js"></script> </body> </html> ); }
}) ); server.use(helmet()); server.use(routerHandler);
app.prepare().then(async () => { const server = express(); server.use(helmet({ contentSecurityPolicy: false })); server.use(compression()); server.use(express.json());
function configureMiddlewares(app) { app.use(helmet()); app.use(bodyParser.json()); app.use(bodyParser.urlencoded({ extended: false })); app.use(logfmt.requestLogger()); }
/** * Setup security middleware. * @private */ setupMiddlewareSecurity_() { this.getServer() .getEngine() .use(helmet()); }
use(request: Request, response: Response, next: () => void) { const req: any = request; const res: any = response; this.helmet(req, res, next); }
app.prepare().then(async () => { const server = express(); server.use(helmet({ contentSecurityPolicy: false })); server.use(compression()); server.use(express.json());
/* TODO: add debug log... */ /** * * @param {Object} helmetConfig - @see: https://github.com/venables/koa-helmet#usage * @returns {Function} helmet middleware */ function koaHelmetMWFactory(helmetConfig) { return helmet(helmetConfig || {}); }