From 3bf0a0b47dd5597738a9e50e80e4f1d7d8c8f08a Mon Sep 17 00:00:00 2001 From: Afzal Ahmad Date: Tue, 17 Nov 2026 14:59:22 +0100 Subject: [PATCH] OPS-12.5: apps/playground is a dev sandbox, drop vercel.json The security headers for vite preview move into vite.config.ts; READMEs point to the public playground repository. --- apps/playground/README.md | 27 +++++---------------------- apps/playground/vercel.json | 18 ------------------ apps/playground/vite.config.ts | 17 ++++++++++------- 3 files changed, 15 insertions(+), 47 deletions(-) delete mode 100644 apps/playground/vercel.json diff --git a/apps/playground/README.md b/apps/playground/README.md index 791cb6b..8c998db 100644 --- a/apps/playground/README.md +++ b/apps/playground/README.md @@ -1,4 +1,6 @@ -# react-data-export playground +# react-data-export playground (dev sandbox) + +> **Dev sandbox, not deployed.** This app runs in CI (tests and build) and locally. It is not deployed anywhere. The public playground is a separate repository, [`securedeveloper/react-data-export-playground`](https://github.com/securedeveloper/react-data-export-playground), live at https://react-data-export-playground.vercel.app/. It installs the published package from npm. A Vite + React 19 app that runs the real library in the browser. It is private and never published to npm. @@ -7,7 +9,7 @@ A Vite + React 19 app that runs the real library in the browser. It is private a - **`useExcelExport`**, the hook, with its status, progress, the saved file's size, and a Cancel button while it runs. - **Table**: a rendered HTML `` (a two-row header with `rowspan`/`colspan`, typed `data-type`/`data-numfmt` cells, a link, a `data-export-ignore` row, a `hidden` row, a footer; `src/demo-table.tsx`) exported with `` and with `useTableExport(ref)` behind a custom button. A format choice and a computed-styles toggle, and a preview of the sheet `fromTable` builds from it. -The app imports the workspace package from its TypeScript sources (`vite.config.ts`), so it always matches the branch. Nothing leaves the browser: there are no uploads, analytics, cookies, CDNs or external requests. `vercel.json` sets a strict Content-Security-Policy (`'self'` only), and `vite preview` serves the same headers, so the CSP is exercised locally. +The app imports the workspace package from its TypeScript sources (`vite.config.ts`), so it always matches the branch. Nothing leaves the browser: there are no uploads, analytics, cookies, CDNs or external requests. `vite.config.ts` gives `vite preview` a strict Content-Security-Policy (`'self'` only) and the other security headers, so the CSP gets tested locally. ## Commands (from the repo root) @@ -16,24 +18,5 @@ npm ci npm run dev -w playground # http://localhost:5173 npm test -w playground # option mapping and preview grid (Vitest) npm run build -w playground # → apps/playground/dist -npm run preview -w playground # serves dist with the production headers +npm run preview -w playground # serves dist with the security headers ``` - -## Deploying on Vercel (for Afzal; the project is not created yet) - -Create a project from `securedeveloper/react-data-export` with: - -| Setting | Value | -|---|---| -| Project name | `react-data-export-playground` (gives `react-data-export-playground.vercel.app`) | -| Root Directory | `apps/playground` | -| Framework preset | Vite (also set in `vercel.json`) | -| Install command | `cd ../.. && npm ci` (from `vercel.json`: installs the whole workspace) | -| Build command | `npm run build` (from `vercel.json`) | -| Output directory | `dist` (from `vercel.json`) | -| Node.js version | 24.x (the workspace needs Node ^22.22.2, ^24.15.0 or ≥ 26) | -| Production branch | `main` | - -- "Include files outside the root directory in the Build Step" must stay enabled (Vercel's default), because the app builds the library from `../../packages/react-data-export/src`. -- No environment variables are needed. -- The security headers come from `vercel.json`. After the first deploy, check them with `curl -sI https://react-data-export-playground.vercel.app/ | grep -i content-security`. diff --git a/apps/playground/vercel.json b/apps/playground/vercel.json deleted file mode 100644 index fb3e916..0000000 --- a/apps/playground/vercel.json +++ /dev/null @@ -1,18 +0,0 @@ -{ - "$schema": "https://openapi.vercel.sh/vercel.json", - "framework": "vite", - "installCommand": "cd ../.. && npm ci", - "buildCommand": "npm run build", - "outputDirectory": "dist", - "headers": [ - { - "source": "/(.*)", - "headers": [ - { "key": "Content-Security-Policy", "value": "default-src 'self'; script-src 'self'; style-src 'self'; img-src 'self' data:; connect-src 'self'; worker-src 'self'; object-src 'none'; base-uri 'none'; form-action 'none'; frame-ancestors 'none'" }, - { "key": "Referrer-Policy", "value": "no-referrer" }, - { "key": "X-Content-Type-Options", "value": "nosniff" }, - { "key": "Permissions-Policy", "value": "camera=(), microphone=(), geolocation=(), interest-cohort=()" } - ] - } - ] -} diff --git a/apps/playground/vite.config.ts b/apps/playground/vite.config.ts index ab11fc6..070aea1 100644 --- a/apps/playground/vite.config.ts +++ b/apps/playground/vite.config.ts @@ -1,4 +1,3 @@ -import { readFileSync } from 'node:fs'; import { fileURLToPath } from 'node:url'; import react from '@vitejs/plugin-react'; import { defineConfig, type UserConfig } from 'vite'; @@ -6,13 +5,17 @@ import { defineConfig, type UserConfig } from 'vite'; // Resolve the library from source so the playground always matches the branch // it is built from, without a separate package build step. The packed tarball // (what npm users get) is covered by the smoke test and the bundler matrix. -// -// `vite preview` serves the same security headers as Vercel (vercel.json), so -// the Content-Security-Policy is exercised locally before a deploy. -const vercel = JSON.parse(readFileSync(new URL('./vercel.json', import.meta.url), 'utf8')) as { - headers: Array<{ headers: Array<{ key: string; value: string }> }>; + +// `vite preview` serves a strict Content-Security-Policy and the other security +// headers (they used to live in vercel.json), so the sandbox and its tests +// exercise the CSP. This app is not deployed; the public playground, +// securedeveloper/react-data-export-playground, sets its own headers. +const headers: Record = { + 'Content-Security-Policy': "default-src 'self'; script-src 'self'; style-src 'self'; img-src 'self' data:; connect-src 'self'; worker-src 'self'; object-src 'none'; base-uri 'none'; form-action 'none'; frame-ancestors 'none'", + 'Referrer-Policy': 'no-referrer', + 'X-Content-Type-Options': 'nosniff', + 'Permissions-Policy': 'camera=(), microphone=(), geolocation=(), interest-cohort=()', }; -const headers = Object.fromEntries(vercel.headers.flatMap((h) => h.headers.map(({ key, value }) => [key, value]))); const config: UserConfig = defineConfig({ plugins: [react()],