-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathaddCSP.ts
31 lines (27 loc) · 1.45 KB
/
addCSP.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
// import { readFile, writeFile } from "fs";
// eslint-disable-next-line
const fs = require("fs");
const filePath = "dist/index.html";
const searchString = '<link rel="canonical" href="https://wormholescan.io/">';
const insertText = `<meta http-equiv="Content-Security-Policy" content="default-src 'self'; upgrade-insecure-requests; script-src 'self' 'unsafe-inline' 'wasm-unsafe-eval' 'unsafe-eval' https://www.google-analytics.com https://ssl.google-analytics.com https://www.googletagmanager.com; img-src 'self' blob: https: ipfs: data: https://www.google-analytics.com https://www.googletagmanager.com; connect-src *; style-src 'self' 'unsafe-inline' https://fonts.googleapis.com; font-src 'self' https://fonts.gstatic.com; object-src 'none'; base-uri 'self'; form-action 'self';" />`;
fs.readFile(filePath, "utf8", (err, data) => {
if (err) {
console.error("Error reading file to add CSP:", err);
return;
}
// Check if the file contains the search string
if (data.includes(searchString)) {
// Insert the text after the search string
const modifiedData = data.replace(searchString, searchString + insertText);
// Write the modified data back to the file
fs.writeFile(filePath, modifiedData, "utf8", err => {
if (err) {
console.error("Error inserting CSP:", err);
} else {
console.log("CSP inserted successfully!");
}
});
} else {
console.log("Error inserting CSP, didnt found search text");
}
});