Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions .github/workflows/pages.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: pages
on:
push:
branches: [master]
paths:
- "apps/site/**"
- "packages/core/**"
- "pnpm-lock.yaml"
- ".github/workflows/pages.yml"
workflow_dispatch:

permissions:
contents: read
pages: write
id-token: write

concurrency:
group: pages
cancel-in-progress: true

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: pnpm/action-setup@v4
- uses: actions/setup-node@v4
with: { node-version: 22, cache: pnpm }
- run: pnpm install --frozen-lockfile
- run: pnpm --filter @enspack/core build
# Demo fixtures until the Sepolia indexer is reachable from the public internet.
- run: pnpm --filter @enspack/site build
env:
VITE_BASE: /enspack/
VITE_DATA_SOURCE: demo
VITE_CHAIN: sepolia
- uses: actions/configure-pages@v5
with: { enablement: true }
- uses: actions/upload-pages-artifact@v3
with: { path: apps/site/dist }

deploy:
needs: build
runs-on: ubuntu-latest
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
steps:
- id: deployment
uses: actions/deploy-pages@v4
10 changes: 10 additions & 0 deletions apps/site/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ into the browser bundle (it would pull viem and IPFS).
| `VITE_REGISTRAR_URL` | `https://registrar.enspack.dev` | Registrar base URL (attestations, claim-page link) |
| `VITE_CHAIN` | `sepolia` | `sepolia` \| `mainnet`; drives the testnet banner and explorer / ENS-app links |
| `VITE_DATA_SOURCE` | `http` | `http` \| `demo`; `demo` serves the recorded fixtures in-app |
| `VITE_BASE` | `/` | Build-time public base path (`/enspack/` on GitHub Pages); the router basename follows it |

## Develop

Expand All @@ -36,6 +37,15 @@ pnpm --filter @enspack/site build
pnpm --filter @enspack/site preview
```

## Deploy (GitHub Pages, preview)

`.github/workflows/pages.yml` builds the site in demo mode with
`VITE_BASE=/enspack/` on every push to `master` that touches `apps/site` and
publishes it to <https://jefflau.github.io/enspack/>. `pnpm build` also writes
`dist/404.html` (a copy of `index.html`, since Pages has no rewrites) and
`dist/.nojekyll`. Pages must be set to "GitHub Actions" as the source once
(Settings → Pages); the workflow attempts to enable it itself.

## Deploy (Cloudflare Pages)

Hosting target is `enspack.dev`. DNS and the Pages project are manual.
Expand Down
2 changes: 1 addition & 1 deletion apps/site/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
},
"scripts": {
"dev": "vite",
"build": "vite build",
"build": "vite build && node scripts/spa-fallback.mjs",
"preview": "vite preview",
"typecheck": "tsc --noEmit -p tsconfig.json",
"test": "vitest run",
Expand Down
5 changes: 5 additions & 0 deletions apps/site/scripts/spa-fallback.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// GitHub Pages has no rewrite rules: serving index.html as 404.html lets deep links reach the router.
import { copyFileSync, writeFileSync } from "node:fs";

copyFileSync("dist/index.html", "dist/404.html");
writeFileSync("dist/.nojekyll", "");
6 changes: 6 additions & 0 deletions apps/site/src/lib/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,9 @@ export function readConfig(env: ImportMetaEnv = import.meta.env): SiteConfig {
}

export const config: SiteConfig = readConfig();

/** react-router wants the base path without a trailing slash; Vite's BASE_URL always has one. */
export function routerBasename(baseUrl: string): string {
const trimmed = baseUrl.replace(/\/+$/, "");
return trimmed === "" ? "/" : trimmed;
}
3 changes: 2 additions & 1 deletion apps/site/src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { createRoot } from "react-dom/client";
import { BrowserRouter } from "react-router";
import { App } from "./app.js";
import { ClientProvider } from "./lib/client-context.js";
import { routerBasename } from "./lib/config.js";
import "./styles/tokens.css";
import "./styles/global.css";

Expand All @@ -11,7 +12,7 @@ if (root === null) throw new Error("missing #root");

createRoot(root).render(
<StrictMode>
<BrowserRouter>
<BrowserRouter basename={routerBasename(import.meta.env.BASE_URL)}>
<ClientProvider>
<App />
</ClientProvider>
Expand Down
8 changes: 7 additions & 1 deletion apps/site/test/lib.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { describe, expect, it, vi } from "vitest";
import { ApiError } from "../src/lib/api.js";
import { FixtureIndexClient, HttpIndexClient } from "../src/lib/client.js";
import { readConfig } from "../src/lib/config.js";
import { readConfig, routerBasename } from "../src/lib/config.js";
import { ensAppUrl, firstLabel, formatBytes, shortHex } from "../src/lib/format.js";
import { demoFixtures } from "./helpers.js";

Expand All @@ -13,6 +13,12 @@ describe("config", () => {
expect(c.indexUrl).toBe("https://idx.example");
});

it("derives the router basename from Vite's BASE_URL", () => {
expect(routerBasename("/")).toBe("/");
expect(routerBasename("/enspack/")).toBe("/enspack");
expect(routerBasename("/enspack")).toBe("/enspack");
});

it("honours mainnet + demo", () => {
const c = readConfig({ VITE_CHAIN: "mainnet", VITE_DATA_SOURCE: "demo" } as ImportMetaEnv);
expect(c.chain).toBe("mainnet");
Expand Down
2 changes: 2 additions & 0 deletions apps/site/vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import react from "@vitejs/plugin-react";
import { defineConfig } from "vite";

// VITE_BASE lets the same bundle serve from a sub-path (GitHub Pages: "/enspack/") or the root.
export default defineConfig({
base: process.env.VITE_BASE ?? "/",
plugins: [react()],
build: { target: "es2022", sourcemap: true },
});
Loading