🔒 Add Content-Security-Policy header

This commit is contained in:
Yann Bertrand 2020-09-05 15:26:34 +02:00
parent 8e97594e5f
commit d67ca17bd4
No known key found for this signature in database
GPG key ID: F87B5B748AB00DAE
4 changed files with 17 additions and 0 deletions

View file

@ -85,6 +85,12 @@ Thank you! I built it using [VuePress](https://vuepress.vuejs.org/). I liked the
"
`;
exports[`write-tree no categories should write the netlify _headers file 1`] = `
"/*
Content-Security-Policy: default-src 'self'; style-src 'self' 'unsafe-inline';
"
`;
exports[`write-tree one category, no page with image should write a category/readme.md file using the category template 1`] = `
"# Category

View file

@ -0,0 +1,2 @@
/*
Content-Security-Policy: default-src 'self'; style-src 'self' 'unsafe-inline';

View file

@ -22,6 +22,10 @@ module.exports = (defaults, destinationPath) => {
fs.copyFileSync('./templates/.vuepress/styles/index.styl', `${destinationPath}/.vuepress/styles/index.styl`)
fs.copyFileSync('./templates/.vuepress/styles/palette.styl', `${destinationPath}/.vuepress/styles/palette.styl`)
const netlifyHeadersTemplate = fs.readFileSync('./templates/.vuepress/public/_headers.handlebars', 'utf8')
const netlifyHeadersContent = Handlebars.compile(netlifyHeadersTemplate)()
fs.writeFileSync(`${destinationPath}/.vuepress/public/_headers`, netlifyHeadersContent)
const homeTemplate = fs.readFileSync('./templates/home.md.handlebars', 'utf8')
const rootReadmeContent = Handlebars.compile(homeTemplate)(defaults)
fs.writeFileSync(`${destinationPath}/readme.md`, rootReadmeContent)

View file

@ -36,6 +36,11 @@ describe('write-tree', () => {
})
})
it('should write the netlify _headers file', () => {
const netlifyHeadersContent = readFile(`${destinationPath}/.vuepress/public/_headers`)
expect(netlifyHeadersContent).toMatchSnapshot()
})
it('should write an empty readme.md file using the home template', () => {
const rootReadmeContent = readFile(`${destinationPath}/readme.md`)
expect(rootReadmeContent).toMatchSnapshot()