|
| 1 | +# Deploying Codex Pet Pause |
| 2 | + |
| 3 | +[简体中文](DEPLOYMENT.zh-CN.md) |
| 4 | + |
| 5 | +## Requirements |
| 6 | + |
| 7 | +Use Node.js `>=22.12.0` and npm. Start from a clean checkout so the lockfile is respected: |
| 8 | + |
| 9 | +```bash |
| 10 | +npm ci |
| 11 | +``` |
| 12 | + |
| 13 | +## Build once, host anywhere |
| 14 | + |
| 15 | +For a normal site served from the domain root, create the production files with: |
| 16 | + |
| 17 | +```bash |
| 18 | +npm run build |
| 19 | +``` |
| 20 | + |
| 21 | +Upload the contents of `dist/` to any static host. This is a static Vite PWA: no application server or database is required. |
| 22 | + |
| 23 | +## GitHub Pages |
| 24 | + |
| 25 | +This repository includes [the Pages deployment workflow](../.github/workflows/deploy-pages.yml). On every push to `main`, it installs dependencies, runs checks, builds the Pages variant, verifies it, and deploys `dist/`. |
| 26 | + |
| 27 | +In the repository, open **Settings → Pages** and choose **GitHub Actions** as the source. After the workflow succeeds, the site is available at [https://ccofallen.github.io/codex-pet-pause/](https://ccofallen.github.io/codex-pet-pause/). |
| 28 | + |
| 29 | +GitHub Pages hosts this project below `/codex-pet-pause/`, so its workflow runs: |
| 30 | + |
| 31 | +```bash |
| 32 | +npm run build:pages |
| 33 | +``` |
| 34 | + |
| 35 | +That build sets the matching `/codex-pet-pause/` base. Do not upload a root-path build to that subpath. |
| 36 | + |
| 37 | +## Vercel |
| 38 | + |
| 39 | +Create a Vercel project from this repository. Use the following project settings: |
| 40 | + |
| 41 | +- Build Command: `npm run build` |
| 42 | +- Output Directory: `dist` |
| 43 | + |
| 44 | +This root-path build is appropriate when the project is served at the domain root. If you intentionally serve it under a Vercel subpath, follow the subpath guidance in [Nginx and other static servers](#nginx-and-other-static-servers) instead. |
| 45 | + |
| 46 | +## Netlify |
| 47 | + |
| 48 | +Create a Netlify site from this repository. Set: |
| 49 | + |
| 50 | +- Build command: `npm run build` |
| 51 | +- Publish directory: `dist` |
| 52 | + |
| 53 | +For a root deployment, Netlify can publish the generated files directly. A subpath deployment needs both a matching build base and host-side fallback, as described below. |
| 54 | + |
| 55 | +## Nginx and other static servers |
| 56 | + |
| 57 | +For a root deployment, copy the contents of `dist/` to the server's static directory and configure the single-page-app fallback: |
| 58 | + |
| 59 | +```nginx |
| 60 | +location / { |
| 61 | + try_files $uri $uri/ /index.html; |
| 62 | +} |
| 63 | +``` |
| 64 | + |
| 65 | +The block above is for a root deployment only. To host at a custom subpath such as `/breaks/`, build with a matching `VITE_BASE_PATH` through a Vite mode or equivalent configuration, then serve the same prefix with a matching Nginx `location` and fallback. For example, place `VITE_BASE_PATH=/breaks/` in the environment file used by the chosen Vite mode, rebuild, and make the fallback resolve to that subpath's `index.html`. A root build with a subpath fallback—or a subpath build served at the root—will request the wrong asset and navigation paths. |
| 66 | + |
| 67 | +Other static servers need the same two pieces: publish the files from `dist/`, and rewrite client-side routes to the `index.html` for the exact prefix being served. |
| 68 | + |
| 69 | +## Windows, Linux, and macOS notes |
| 70 | + |
| 71 | +The npm commands in this guide work in PowerShell, Command Prompt, macOS Terminal, and Linux shells: |
| 72 | + |
| 73 | +```bash |
| 74 | +npm ci |
| 75 | +npm run build |
| 76 | +``` |
| 77 | + |
| 78 | +Prefer a Vite mode or an environment file for `VITE_BASE_PATH` so the configuration is portable; inline environment-variable syntax differs between Windows and POSIX shells. Use forward slashes in the base path, for example `/breaks/`. |
| 79 | + |
| 80 | +## Updating an existing deployment |
| 81 | + |
| 82 | +Pull the intended revision, reinstall dependencies, rebuild, and replace the previously published `dist/` files: |
| 83 | + |
| 84 | +```bash |
| 85 | +npm ci |
| 86 | +npm run build |
| 87 | +``` |
| 88 | + |
| 89 | +For GitHub Pages, push the revision to `main` and let the included workflow rebuild and deploy it. Keep the same build base as the published URL; use `npm run build:pages` only for the `/codex-pet-pause/` Pages target. |
| 90 | + |
| 91 | +## HTTPS, notifications, and PWA behavior |
| 92 | + |
| 93 | +Production deployments must use HTTPS. Browsers require a secure context for reliable notifications, service workers, and PWA installation; `localhost` is the local-development exception. Users must also grant notification permission, and browser or operating-system power-saving policies can delay background work. |
| 94 | + |
| 95 | +Reminders run only while the app remains open in a browser context. Closing the tab or browser stops reminders; the PWA does not keep a background reminder process running after the browser has closed. |
| 96 | + |
| 97 | +## Troubleshooting |
| 98 | + |
| 99 | +- **Assets or pages return 404 under a subpath:** rebuild with a `VITE_BASE_PATH` that exactly matches the served prefix and configure that prefix's static location and SPA fallback. |
| 100 | +- **Direct navigation returns a server 404:** add the root `try_files` fallback above, or its equivalent for the deployed subpath. |
| 101 | +- **Notifications do not appear:** confirm HTTPS, grant permission in the browser, and check system notification and focus settings. |
| 102 | +- **An older version remains visible:** refresh after the deployment has finished and clear the site's cached data or unregister its service worker if necessary. |
| 103 | +- **The Pages URL is wrong:** confirm Settings → Pages uses GitHub Actions and that the Pages workflow built with `/codex-pet-pause/`. |
0 commit comments