-
Notifications
You must be signed in to change notification settings - Fork 649
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added Scripts to Generate headers for CF Pages (#10535)
- Loading branch information
Showing
4 changed files
with
31 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -67,3 +67,4 @@ src/pluginMap.ts | |
# Federation Temp files | ||
/.__mf__temp | ||
public/sbom/* | ||
public/_headers |
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,27 @@ | ||
import { writeFile } from "fs/promises"; | ||
import path from "path"; | ||
|
||
const headers = process.env.HEADERS; | ||
const header_folder = path.join(__dirname, "..", "public"); | ||
|
||
async function writeHeaders() { | ||
if (!headers) { | ||
console.warn("HEADERS environment variable is not set."); | ||
process.exit(0); | ||
} | ||
|
||
console.log("HEADERS environment variable is set."); | ||
const headersPath = path.join(header_folder, "_headers"); | ||
console.log(`Writing headers to file at path: ${headersPath}`); | ||
|
||
try { | ||
await writeFile(headersPath, headers, "utf-8"); | ||
console.log("Headers written to file successfully."); | ||
process.exit(0); | ||
} catch (error) { | ||
console.error("Error writing headers to file:", error); | ||
process.exit(0); | ||
} | ||
} | ||
|
||
writeHeaders(); |