diff --git a/.env b/.env index 2c8b73fb65a..2e32ac97bbf 100644 --- a/.env +++ b/.env @@ -5,6 +5,7 @@ REACT_APP_META_DESCRIPTION="Revolutionizing EMR with AI: Open Healthcare Network REACT_APP_COVER_IMAGE=https://cdn.ohc.network/care_logo.svg REACT_APP_COVER_IMAGE_ALT=https://cdn.ohc.network/care_logo.svg REACT_PUBLIC_URL=https://care.ohc.network +HEADERS="/*\n Strict-Transport-Security: max-age=63072000; includeSubDomains; preload\n X-XSS-Protection: 1; mode=block\n X-Frame-Options: SAMEORIGIN\n X-Content-Type-Options: nosniff\n Referrer-Policy: strict-origin-when-cross-origin\n Permissions-Policy: geolocation=(self), microphone=()" # Care API URL without the /api prefix REACT_CARE_API_URL=https://careapi.ohc.network diff --git a/.gitignore b/.gitignore index 17e2f8f71d7..fb30d613042 100644 --- a/.gitignore +++ b/.gitignore @@ -67,3 +67,4 @@ src/pluginMap.ts # Federation Temp files /.__mf__temp public/sbom/* +public/_headers diff --git a/package.json b/package.json index a84562ddae6..8edf10ae562 100644 --- a/package.json +++ b/package.json @@ -35,7 +35,7 @@ "supported-browsers": "node ./scripts/generate-supported-browsers.mjs", "build": "npm run setup && npm run build:meta && npm run supported-browsers && npm run build:react", "setup": "tsx scripts/setup-care-apps.ts", - "postinstall": "tsx scripts/install-platform-deps.ts && tsx scripts/generate-sbom-data.ts", + "postinstall": "tsx scripts/install-platform-deps.ts && tsx scripts/generate-sbom-data.ts && tsx scripts/generate-headers.ts", "test": "snyk test", "cypress:open": "cross-env NODE_ENV=development cypress open", "cypress:run": "cross-env NODE_ENV=development cypress run", @@ -210,4 +210,4 @@ "node": ">=22.8.0" }, "packageManager": "npm@10.9.2" -} \ No newline at end of file +} diff --git a/scripts/generate-headers.ts b/scripts/generate-headers.ts new file mode 100644 index 00000000000..5dbc803370c --- /dev/null +++ b/scripts/generate-headers.ts @@ -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();