This repository was archived by the owner on Dec 13, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
edfff08
commit ebb71ac
Showing
7 changed files
with
121 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
const generatedBy = | ||
'# Generated by https://github.com/dansmaculotte/nuxt-security' | ||
|
||
const contactOutput = contact => `Contact: ${contact}` | ||
const encryptionOuput = url => `Encryption: ${url}` | ||
const acknowledgmentOuput = url => `Acknowledgments: ${url}` | ||
const languagesOutput = languages => `Preferred-Languages: ${languages}` | ||
const canonicalOutput = url => `Canonical: ${url}` | ||
const policyOuput = url => `Policy: ${url}` | ||
const hiringOuput = url => `Hiring: ${url}` | ||
|
||
const makeArray = arr => (Array.isArray(arr) ? arr : [arr]) | ||
|
||
module.exports = ({ | ||
contacts, | ||
encryptions, | ||
acknowledgments, | ||
preferredLanguages, | ||
canonical, | ||
policies, | ||
hirings | ||
}) => { | ||
const contents = [generatedBy] | ||
|
||
makeArray(contacts).map(contact => contents.push(contactOutput(contact))) | ||
|
||
makeArray(encryptions).map(encryption => | ||
contents.push(encryptionOuput(encryption)) | ||
) | ||
|
||
makeArray(acknowledgments).map(acknowledgment => | ||
contents.push(acknowledgmentOuput(acknowledgment)) | ||
) | ||
|
||
if (preferredLanguages && preferredLanguages.length) { | ||
contents.push(languagesOutput(makeArray(preferredLanguages).join(','))) | ||
} | ||
|
||
if (canonical) { | ||
contents.push(canonicalOutput(canonical)) | ||
} | ||
|
||
makeArray(policies).map(policy => contents.push(policyOuput(policy))) | ||
|
||
makeArray(hirings).map(hiring => contents.push(hiringOuput(hiring))) | ||
|
||
return contents.join('\n') | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
const { resolve } = require('path') | ||
const { writeFileSync, existsSync, mkdirSync } = require('fs') | ||
|
||
module.exports = function(options, fileContents, nuxtInstance) { | ||
const { | ||
rootDir, | ||
generate: { dir: generateDir } | ||
} = nuxtInstance.options | ||
|
||
// generate .well-know/security.txt in dist | ||
nuxtInstance.nuxt.hook('generate:done', () => { | ||
const generateDirPath = resolve(rootDir, generateDir, options.wellKnowDir) | ||
const generateFilePath = resolve(generateDirPath, options.fileName) | ||
|
||
if (!existsSync(generateDirPath)) { | ||
mkdirSync(generateDirPath) | ||
} | ||
|
||
writeFileSync(generateFilePath, fileContents) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
module.exports = function(options, fileContents, nuxtInstance) { | ||
// render .well-know/security.txt via SSR | ||
nuxtInstance.addServerMiddleware({ | ||
path: options.wellKnowDir + '/' + options.fileName, | ||
handler(req, res) { | ||
res.setHeader('Content-Type', 'text/plain') | ||
res.end(fileContents) | ||
} | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters