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

Commit

Permalink
feat: add HSTS
Browse files Browse the repository at this point in the history
  • Loading branch information
gaelreyrol committed Jan 28, 2020
1 parent 49593b0 commit 1f95123
Show file tree
Hide file tree
Showing 6 changed files with 10,781 additions and 19 deletions.
15 changes: 11 additions & 4 deletions example/nuxt.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,16 @@ module.exports = {
resourceHints: false
},
modules: [
{ handler: require('../') }
{
handler: require('../'),
options: {
hsts: {
maxAge: 15552000,
includeSubDomains: true,
preload: true
}
}
}
],
buildModules: [
'@nuxtjs/dotenv',
]
buildModules: ['@nuxtjs/dotenv']
}
4 changes: 1 addition & 3 deletions example/pages/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,5 @@
</template>

<script>
export default {
}
export default {}
</script>
20 changes: 13 additions & 7 deletions lib/module.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
const { resolve } = require('path')
const hsts = require('hsts')

module.exports = async function (moduleOptions) {
module.exports = function(moduleOptions) {
const defaults = {
hsts: null
}
const options = {
...defaults,
...this.options['nuxt-csp'],
...moduleOptions
}

this.addPlugin({
src: resolve(__dirname, 'plugin.js'),
fileName: 'nuxt-csp.js',
options
})
const configureHsts = options => {
return hsts(options)
}

if (options.hsts) {
this.addServerMiddleware(configureHsts(options.hsts))
}
}

module.exports.meta = require('../package.json')
4 changes: 0 additions & 4 deletions lib/plugin.js

This file was deleted.

10 changes: 9 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@
"name": "@dansmaculotte/nuxt-csp",
"version": "0.0.0",
"description": "Module for Nuxt.js to configure CSP headers",
"keywords": [
"nuxt",
"nuxt-module",
"csp",
"content-security-policy"
],
"repository": "dansmaculotte/nuxt-csp",
"license": "MIT",
"contributors": [
Expand All @@ -19,7 +25,9 @@
"release": "yarn test && standard-version && git push --follow-tags && npm publish",
"test": "yarn lint && jest"
},
"dependencies": {},
"dependencies": {
"hsts": "^2.2.0"
},
"devDependencies": {
"@babel/core": "latest",
"@babel/preset-env": "latest",
Expand Down
Loading

0 comments on commit 1f95123

Please sign in to comment.