ci: GitHub Pages now serves a redirect to loto.miti99.com

Replace the full build+publish flow with a tiny inline shell step that
emits two static HTML pages (out/index.html and out/master/index.html).
Each one carries:

  <meta http-equiv="refresh" content="0; url=https://loto.miti99.com/">
  <script>location.replace("https://loto.miti99.com" + ...)</script>

The script preserves path / query / hash, so
  /loto/                  → loto.miti99.com/
  /loto/master            → loto.miti99.com/master
  /loto/?x=1              → loto.miti99.com/?x=1

Cloudflare Pages stays canonical; this change just stops GH Pages from
serving a stale duplicate of the app and points old links at the live
domain instead.

The build:gh npm script is kept as a manual escape hatch for the rare
case where someone wants to deploy a real GH Pages copy by hand.
This commit is contained in:
tiennm99 committed 2026-04-26 21:19:40 +07:00
1 parent 76ea82a649
commit c743d1cbfe
3 files changed
+66 -24

No files matched your search

+35 -8
View File
@@ -1,4 +1,4 @@
name: Deploy to GitHub Pages
name: Deploy redirect to GitHub Pages
on:
push:
@@ -19,16 +19,43 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
cache: npm
- run: npm ci
- run: npm run build:gh
- name: Generate redirect pages
run: |
set -euo pipefail
DEST="https://loto.miti99.com"
mkdir -p out/master
cat > out/index.html <<HTML
<!doctype html>
<html lang="vi">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Lô tô — đã chuyển sang ${DEST}</title>
<link rel="canonical" href="${DEST}/">
<meta http-equiv="refresh" content="0; url=${DEST}/">
<meta name="robots" content="noindex">
<script>
(function () {
var path = location.pathname.replace(/^\/loto/, "");
location.replace("${DEST}" + path + location.search + location.hash);
})();
</script>
<style>
body { font-family: system-ui, sans-serif; padding: 3rem 1.5rem; text-align: center; color: #475569; }
a { color: #6366f1; }
</style>
</head>
<body>
<p>Trang đã chuyển sang <a href="${DEST}/">${DEST}</a></p>
</body>
</html>
HTML
# Mirror to /master so deep links also redirect cleanly
cp out/index.html out/master/index.html
- uses: actions/configure-pages@v5
- uses: actions/upload-pages-artifact@v3
with:
path: build
path: out
deploy:
needs: build
+30 -15
View File
@@ -32,26 +32,40 @@ pushes to `main` trigger automatic builds + deploys.
No GitHub Actions involved; no repo secrets needed.
## GitHub Pages (parallel auto-deploy)
## GitHub Pages (redirect-only)
`.github/workflows/deploy-github-pages.yml` runs on every push to `main`,
builds with `npm run build:gh` (basePath `/loto`), and publishes `build/`
as a Pages artifact.
`.github/workflows/deploy-github-pages.yml` no longer builds the app.
It generates two tiny HTML pages (`/loto/index.html` and
`/loto/master/index.html`) that immediately redirect to the canonical
URL on Cloudflare Pages.
URL: `https://tiennm99.github.io/loto`.
The redirect uses both `<meta http-equiv="refresh">` (no-JS fallback)
and a tiny inline script that preserves path / query / hash:
CF Pages and GH Pages run in parallel — different URLs, different
artifacts, no conflict. Drop GH Pages by deleting the workflow file.
```js
location.replace("https://loto.miti99.com" + path + search + hash);
```
### Manual GH Pages Deploy
So `tiennm99.github.io/loto/` → `loto.miti99.com/` and
`tiennm99.github.io/loto/master` → `loto.miti99.com/master`.
If you'd rather export by hand:
The redirect runs on every push to `main`. If you want full GH Pages
serving back (instead of the redirect), restore the prior version of
`.github/workflows/deploy-github-pages.yml` from git history — it ran
`npm run build:gh` and uploaded the `build/` artifact.
### Manual GH Pages Build (still available)
If you ever want to build a real GH Pages export by hand:
```bash
npm run build:gh
# upload build/ to the GH Pages target
# upload build/ to the GH Pages target manually
```
`build:gh` script kept as an escape hatch — not used by the automated
redirect workflow.
## Development Environment
### Local Dev
@@ -155,11 +169,12 @@ Generates:
## CI/CD Pipeline
Both providers auto-deploy on push to `main`:
- **Cloudflare Pages** — wired via the CF dashboard, builds with `npm run build`,
publishes to `loto.miti99.com`.
- **GitHub Pages** — wired via `.github/workflows/deploy-github-pages.yml`,
builds with `npm run build:gh`, publishes to `tiennm99.github.io/loto`.
Two pipelines run on push to `main`:
- **Cloudflare Pages** (canonical) — wired via the CF dashboard, builds with
`npm run build`, publishes to `loto.miti99.com`.
- **GitHub Pages** (redirect-only) — wired via
`.github/workflows/deploy-github-pages.yml`, deploys static redirect HTML
that forwards `tiennm99.github.io/loto/*` to `loto.miti99.com/*`.
## Performance Checklist
+1 -1
View File
@@ -31,7 +31,7 @@ State is entirely client-side. Each page/card instance uses a unique localStorag
## Deployment
- **Production**: dual auto-deploy on push to `main` — Cloudflare Pages at `loto.miti99.com` (CF dashboard, root basePath) and GitHub Pages at `tiennm99.github.io/loto` (`.github/workflows/deploy-github-pages.yml`, `/loto` basePath via `npm run build:gh`).
- **Production**: Cloudflare Pages at `loto.miti99.com` (canonical, CF dashboard, root basePath). GitHub Pages serves only a redirect to the canonical URL via `.github/workflows/deploy-github-pages.yml`.
- **Development**: `npm run dev` (local), `npm run dev:codeserver` (code-server via proxy).
- **Build**: `npm run build` generates static export to `build/` directory.