Skip to content

Commit

Permalink
feat(express): make helmet headers configurable
Browse files Browse the repository at this point in the history
this PR makes the sent security headers by hops via helmet
configurable, so that projects that use directly hops as a
"front-facing-server" can set their custom headers.
  • Loading branch information
robertkowalski committed Apr 6, 2022
1 parent ec176ed commit 71bd502
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
5 changes: 5 additions & 0 deletions packages/express/README.md
Expand Up @@ -35,6 +35,7 @@ You may use either `hops serve -p` or its equivalent `NODE_ENV=production hops s
| `port` | `String` | `[PORT]` | _no_ | Specify the Port that Hops should listen on |
| `distDir` | `String` | `'<rootDir>/dist'` | _no_ | The folder from which to serve static assets |
| `gracePeriod` | `number` | `30000` | _no_ | Time to wait (in ms) until killing the server |
| `helmetConfig` | `Object` | `{}` | _no_ | Headers to set or overwrite in helmet |

##### `https`

Expand Down Expand Up @@ -91,6 +92,10 @@ The amount of time (in milliseconds) to wait after receiving a [`SIGTERM`](https
}
```

##### `helmetConfig`

The config to set security http headers via [helmet](https://helmetjs.github.io/).

#### Render Options

This preset has no runtime configuration options.
Expand Down
4 changes: 2 additions & 2 deletions packages/express/mixins/mixin.core.js
Expand Up @@ -37,9 +37,9 @@ class ExpressMixin extends Mixin {
const express = require('express');
const mime = require('mime');
const cookieParser = require('cookie-parser');
const { distDir } = this.config;
const { distDir, helmetConfig = {} } = this.config;
middlewares.preinitial.push(
helmet({ contentSecurityPolicy: false }),
helmet({ contentSecurityPolicy: false, ...helmetConfig }),
cookieParser()
);
middlewares.files.push(
Expand Down
3 changes: 3 additions & 0 deletions packages/express/preset.js
Expand Up @@ -26,5 +26,8 @@ module.exports = {
port: { oneOf: [{ type: 'string' }, { type: 'number' }] },
distDir: { type: 'string', minLength: 1, absolutePath: true },
gracePeriod: { type: 'number' },
helmetConfig: {
type: 'object',
},
},
};

0 comments on commit 71bd502

Please sign in to comment.