Skip to content
This repository was archived by the owner on Dec 13, 2024. It is now read-only.

Commit 1f95123

Browse files
committed
feat: add HSTS
1 parent 49593b0 commit 1f95123

File tree

6 files changed

+10781
-19
lines changed

6 files changed

+10781
-19
lines changed

example/nuxt.config.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,16 @@ module.exports = {
1010
resourceHints: false
1111
},
1212
modules: [
13-
{ handler: require('../') }
13+
{
14+
handler: require('../'),
15+
options: {
16+
hsts: {
17+
maxAge: 15552000,
18+
includeSubDomains: true,
19+
preload: true
20+
}
21+
}
22+
}
1423
],
15-
buildModules: [
16-
'@nuxtjs/dotenv',
17-
]
24+
buildModules: ['@nuxtjs/dotenv']
1825
}

example/pages/index.vue

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,5 @@
55
</template>
66

77
<script>
8-
export default {
9-
10-
}
8+
export default {}
119
</script>

lib/module.js

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,22 @@
1-
const { resolve } = require('path')
1+
const hsts = require('hsts')
22

3-
module.exports = async function (moduleOptions) {
3+
module.exports = function(moduleOptions) {
4+
const defaults = {
5+
hsts: null
6+
}
47
const options = {
8+
...defaults,
59
...this.options['nuxt-csp'],
610
...moduleOptions
711
}
812

9-
this.addPlugin({
10-
src: resolve(__dirname, 'plugin.js'),
11-
fileName: 'nuxt-csp.js',
12-
options
13-
})
13+
const configureHsts = options => {
14+
return hsts(options)
15+
}
16+
17+
if (options.hsts) {
18+
this.addServerMiddleware(configureHsts(options.hsts))
19+
}
1420
}
1521

1622
module.exports.meta = require('../package.json')

lib/plugin.js

Lines changed: 0 additions & 4 deletions
This file was deleted.

package.json

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22
"name": "@dansmaculotte/nuxt-csp",
33
"version": "0.0.0",
44
"description": "Module for Nuxt.js to configure CSP headers",
5+
"keywords": [
6+
"nuxt",
7+
"nuxt-module",
8+
"csp",
9+
"content-security-policy"
10+
],
511
"repository": "dansmaculotte/nuxt-csp",
612
"license": "MIT",
713
"contributors": [
@@ -19,7 +25,9 @@
1925
"release": "yarn test && standard-version && git push --follow-tags && npm publish",
2026
"test": "yarn lint && jest"
2127
},
22-
"dependencies": {},
28+
"dependencies": {
29+
"hsts": "^2.2.0"
30+
},
2331
"devDependencies": {
2432
"@babel/core": "latest",
2533
"@babel/preset-env": "latest",

0 commit comments

Comments
 (0)