mirror of
https://github.com/storytold/artcraft-services.git
synced 2026-11-19 08:53:03 +01:00
Configure artcraft-dashboard for Cloudflare at dashboard.artcraft.team (#408)
## Problem The admin dashboard is deployed only to Netlify (`artcraft-dashboard.netlify.app`), while the rest of the frontends deploy to Cloudflare from this repository. Move it to Cloudflare and serve it at `dashboard.artcraft.team`. ## Change - **`frontend/apps/artcraft-dashboard/wrangler.jsonc`** — `artcraft-dashboard` static-assets Worker: SPA `not_found_handling`, `run_worker_first: ["/api/*"]`, custom domain `dashboard.artcraft.team`. - **`cloudflare_worker/index.ts`** — same-origin `/api/*` proxy to `https://api.storyteller.ai`. The dashboard calls the API with `credentials: "include"`, so its session cookie has to stay first-party; `api.storyteller.ai` is a different site than `dashboard.artcraft.team`, so a direct cross-site call would have the cookie dropped by browsers. This replaces Netlify's `/api/*` rewrite. - **`script/website/cloudflare_app.sh` + root `package.json`** — `ARTCRAFT_APP=artcraft-dashboard`, plus `npm run build:dashboard` / `npm run deploy:dashboard`. - **`_redirects`** moved from `public/` to the app root and copied into `dist/` by `netlify_build.sh`, so the Cloudflare upload never contains the `/* /index.html 200` loop or the external-host proxy that Workers reject. Netlify keeps working unchanged as the rollback target. - **CORS** — `https://dashboard.artcraft.team` allowlisted in `artcraft_admin_dashboard.rs`, the regression table, and the production product-origin test. - **`tsconfig.app.json`** — excludes spec files. `DebugLogCard.spec.ts` imports `vitest`, which only resolved through the parent workspace's `node_modules`; the standalone Cloudflare build never installs those, so `tsc -b` failed. - Docs: dashboard README (deploy, proxy rationale, rollback) and the root README Worker table. ## Cloudflare settings | Setting | Value | |----------------|-----------------------------------| | Build command | `npm run build` | | Deploy command | `npm run deploy` | | Build variable | `ARTCRAFT_APP=artcraft-dashboard` | | Build variable | `NODE_VERSION=22` | `VITE_API_HOST` is deliberately not set: the dashboard keeps calling `/api`, and the Worker proxies it. ## Checklist before cutover - [ ] `artcraft.team` is a zone in the Cloudflare account (Workers custom domains require the zone). - [ ] `artcraft-dashboard` Worker created from this repo with the settings above. - [ ] Domain attached; log in and confirm the session works at `https://dashboard.artcraft.team`. A `*.workers.dev` URL is not CORS-allowlisted, so test through the domain (or add the test host to the CORS config first). - [ ] Netlify site kept for rollback; reverting is pointing the domain back at it. ## Testing - `cargo test -p actix_cors_configs` — 81 passed, including the new `dashboard_domain` case and the allowlist regression table. - `pnpm install --frozen-lockfile && pnpm build` in `frontend/apps/artcraft-dashboard` — succeeds (9014 modules); `dist/` has no `_redirects`. - `wrangler deploy --dry-run --config frontend/apps/artcraft-dashboard/wrangler.jsonc` — clean: 5 assets, `env.ASSETS` binding, no config warnings. - Not run: an actual deploy, since there are no Cloudflare credentials or account access in this environment. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> <!-- coderabbit-ai-generated:v1 --> ## Summary by CodeRabbit * **New Features** * The ArtCraft Admin Dashboard is now available at `dashboard.artcraft.team`, with dashboard API requests routed through the new deployment. * The dashboard’s production origin is now allowed for cross-origin requests. * **Documentation** * Added deployment and build guidance for the dashboard, including its Cloudflare hosting and API routing details. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
This commit is contained in:
1 parent
896824e56f
commit
766ead6629
14 files changed
+183
-10
No files matched your search
@@ -205,14 +205,16 @@ command `npm run build` and the deploy command `npm run deploy`. Each Worker set
|
||||
the `ARTCRAFT_APP` build variable to choose what
|
||||
[`cloudflare_app.sh`](./script/website/cloudflare_app.sh) builds:
|
||||
|
||||
| Worker | `ARTCRAFT_APP` | Hostname | Wrangler config | Build secrets |
|
||||
|---------------------|------------------------------|-----------------------|------------------------------------------------|--------------------------------------------------------------|
|
||||
| `artcraft-services` | `artcraft-website` (default) | `getartcraft.com` | `wrangler.jsonc` | `LAUNCHER_CATALOG_SIGNING_KEY`; optional `LINUX_SIGNING_KEY` |
|
||||
| `artcraft-webapp` | `artcraft-webapp` | `app.getartcraft.com` | `frontend/apps/artcraft-webapp/wrangler.jsonc` | none |
|
||||
| Worker | `ARTCRAFT_APP` | Hostname | Wrangler config | Build secrets |
|
||||
|----------------------|------------------------------|---------------------------|---------------------------------------------------|--------------------------------------------------------------|
|
||||
| `artcraft-services` | `artcraft-website` (default) | `getartcraft.com` | `wrangler.jsonc` | `LAUNCHER_CATALOG_SIGNING_KEY`; optional `LINUX_SIGNING_KEY` |
|
||||
| `artcraft-webapp` | `artcraft-webapp` | `app.getartcraft.com` | `frontend/apps/artcraft-webapp/wrangler.jsonc` | none |
|
||||
| `artcraft-dashboard` | `artcraft-dashboard` | `dashboard.artcraft.team` | `frontend/apps/artcraft-dashboard/wrangler.jsonc` | none |
|
||||
|
||||
The webapp never builds the website, so its Worker needs no signing keys. Its
|
||||
`VITE_*` variables (for example `VITE_GOOGLE_CLIENT_ID`) are build variables, not
|
||||
runtime secrets.
|
||||
runtime secrets. The admin dashboard is a standalone pnpm app and sets
|
||||
`NODE_VERSION=22`; see [its README](./frontend/apps/artcraft-dashboard/README.md).
|
||||
|
||||
## Automated Craft Release Version Updates
|
||||
|
||||
|
||||
@@ -65,6 +65,7 @@ const ALLOWLIST: &[(AddOrigins, Env, &str)] = &[
|
||||
(add_artcraft_3d, Both, "https://brandons-macbook-pro.taild62114.ts.net"),
|
||||
|
||||
// add_artcraft_admin_dashboard
|
||||
(add_artcraft_admin_dashboard, Both, "https://dashboard.artcraft.team"),
|
||||
(add_artcraft_admin_dashboard, Both, "https://artcraft-dashboard.netlify.app"),
|
||||
|
||||
// add_artcraft_desktop
|
||||
|
||||
@@ -3,6 +3,9 @@ use crate::util::netlify_branch_domain_matches::netlify_branch_domain_matches;
|
||||
|
||||
pub fn add_artcraft_admin_dashboard(cors: Cors, _is_production: bool) -> Cors {
|
||||
cors
|
||||
// Production domain (Cloudflare Worker).
|
||||
.allowed_origin("https://dashboard.artcraft.team")
|
||||
// Legacy Netlify project, kept as the rollback target.
|
||||
.allowed_origin("https://artcraft-dashboard.netlify.app")
|
||||
.allowed_origin_fn(|origin, _req_head| {
|
||||
netlify_branch_domain_matches(origin, "artcraft-dashboard.netlify.app")
|
||||
@@ -11,10 +14,18 @@ pub fn add_artcraft_admin_dashboard(cors: Cors, _is_production: bool) -> Cors {
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::testing::{assert_netlify_project, isolated_cors};
|
||||
use crate::testing::{assert_exact_https_origin, assert_netlify_project, isolated_cors};
|
||||
|
||||
use super::add_artcraft_admin_dashboard;
|
||||
|
||||
#[actix_rt::test]
|
||||
async fn dashboard_domain() {
|
||||
for is_production in [true, false] {
|
||||
let cors = isolated_cors(add_artcraft_admin_dashboard, is_production);
|
||||
assert_exact_https_origin(&cors, "https://dashboard.artcraft.team").await;
|
||||
}
|
||||
}
|
||||
|
||||
#[actix_rt::test]
|
||||
async fn netlify_project() {
|
||||
for is_production in [true, false] {
|
||||
|
||||
@@ -121,6 +121,7 @@ mod tests {
|
||||
"https://www.getartcraft.com",
|
||||
"https://artcraft.ai",
|
||||
"https://www.artcraft.ai",
|
||||
"https://dashboard.artcraft.team",
|
||||
"https://artcraft-dashboard.netlify.app",
|
||||
"https://realseedance.com",
|
||||
"https://www.realseedance.com",
|
||||
|
||||
@@ -1,2 +1,50 @@
|
||||
# ArtCraft Admin Dashboard
|
||||
Admin dashboard for managing ArtCraft
|
||||
|
||||
Admin dashboard for managing ArtCraft, served at
|
||||
<https://dashboard.artcraft.team>.
|
||||
|
||||
## Deployment
|
||||
|
||||
Production is a Cloudflare Worker with static assets
|
||||
([`wrangler.jsonc`](./wrangler.jsonc)). Deploy from the repository root:
|
||||
|
||||
```bash
|
||||
npm run build:dashboard
|
||||
npm run deploy:dashboard
|
||||
```
|
||||
|
||||
Workers Builds settings for the `artcraft-dashboard` Worker:
|
||||
|
||||
| Setting | Value |
|
||||
|----------------|-----------------------------------|
|
||||
| Build command | `npm run build` |
|
||||
| Deploy command | `npm run deploy` |
|
||||
| Build variable | `ARTCRAFT_APP=artcraft-dashboard` |
|
||||
| Build variable | `NODE_VERSION=22` |
|
||||
|
||||
`ARTCRAFT_APP` selects this app in
|
||||
[`script/website/cloudflare_app.sh`](../../../script/website/cloudflare_app.sh).
|
||||
Vite 7 needs Node >= 20.19 / 22.12, so `NODE_VERSION=22` is required; it cannot
|
||||
be pinned in the repository because the rest of the workspace builds on the same
|
||||
Node version.
|
||||
|
||||
### `/api` proxy
|
||||
|
||||
[`cloudflare_worker/index.ts`](./cloudflare_worker/index.ts) forwards `/api/*` to
|
||||
`https://api.storyteller.ai`. The dashboard calls the API with
|
||||
`credentials: "include"`, so the session cookie has to be first-party; a direct
|
||||
cross-site call would be dropped by browsers. The Worker forwards the browser's
|
||||
`Origin`, so `https://dashboard.artcraft.team` must stay in the API's CORS
|
||||
allowlist
|
||||
([`artcraft_admin_dashboard.rs`](../../../crates/lib/actix_cors_configs/src/configs/artcraft_admin_dashboard.rs)).
|
||||
The Worker's `*.workers.dev` host is not on that allowlist, so API calls only
|
||||
work through `dashboard.artcraft.team` — add the test host to the CORS config if
|
||||
you need to exercise a deployment before attaching the domain.
|
||||
|
||||
### Netlify rollback
|
||||
|
||||
[`netlify.toml`](./netlify.toml) and [`script/netlify_build.sh`](./script/netlify_build.sh)
|
||||
are kept so the previous site can still build and serve. Netlify's routing rules
|
||||
live in [`_redirects`](./_redirects) at the app root and are copied into `dist/`
|
||||
by that script; Cloudflare does not get them, because Workers reject the
|
||||
`/* /index.html 200` fallback and cannot proxy external hosts from `_redirects`.
|
||||
File renamed without changes.
@@ -0,0 +1,40 @@
|
||||
// Cloudflare Worker for dashboard.artcraft.team.
|
||||
//
|
||||
// The dashboard is a static Vite SPA, so the Worker serves `dist/` and only steps
|
||||
// in for `/api/*`. The dashboard calls the API with `credentials: "include"`, and
|
||||
// api.storyteller.ai is a different site than dashboard.artcraft.team, so the
|
||||
// session cookie would be third-party and browsers would drop it. Proxying keeps
|
||||
// every API call first-party — the same thing Netlify's `/api/*` rewrite did.
|
||||
|
||||
const API_ORIGIN = "https://api.storyteller.ai";
|
||||
const API_PREFIX = "/api";
|
||||
|
||||
// Minimal shape of the static-assets binding declared in wrangler.jsonc. Wrangler
|
||||
// bundles this file itself, so no worker runtime types are needed here.
|
||||
interface AssetsBinding {
|
||||
fetch(request: Request): Promise<Response>;
|
||||
}
|
||||
|
||||
interface Env {
|
||||
ASSETS: AssetsBinding;
|
||||
}
|
||||
|
||||
export default {
|
||||
async fetch(request: Request, env: Env): Promise<Response> {
|
||||
const url = new URL(request.url);
|
||||
|
||||
if (url.pathname === API_PREFIX || url.pathname.startsWith(`${API_PREFIX}/`)) {
|
||||
return fetch(proxyToApi(request, url));
|
||||
}
|
||||
|
||||
return env.ASSETS.fetch(request);
|
||||
},
|
||||
};
|
||||
|
||||
function proxyToApi(request: Request, url: URL): Request {
|
||||
const upstream = new URL(API_ORIGIN);
|
||||
upstream.pathname = url.pathname.slice(API_PREFIX.length) || "/";
|
||||
upstream.search = url.search;
|
||||
|
||||
return new Request(upstream, request);
|
||||
}
|
||||
@@ -1,5 +1,7 @@
|
||||
# Netlify configuration for the ArtCraft admin dashboard.
|
||||
#
|
||||
# Retained only as the rollback target: production now serves from the Cloudflare
|
||||
# Worker at dashboard.artcraft.team (see README.md).
|
||||
# Set up the Netlify site exactly like the other apps in this workspace:
|
||||
# * Base directory: frontend (the Nx workspace root)
|
||||
# * Build command: bash ./apps/artcraft-dashboard/script/netlify_build.sh
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -euxo pipefail
|
||||
|
||||
# Build the ArtCraft admin dashboard for Cloudflare Workers.
|
||||
#
|
||||
# Run from anywhere: this builds inside the app's own folder, which is deliberate
|
||||
# (see netlify_build.sh) — the dashboard is a standalone pnpm app with React 19 +
|
||||
# Vite 7, outside the Nx/npm workspace.
|
||||
|
||||
cd "$(dirname "$0")/.."
|
||||
|
||||
echo "Building artcraft-dashboard (standalone pnpm build)"
|
||||
|
||||
# Use the pnpm version pinned in package.json's `packageManager` field, via
|
||||
# corepack. Disable the interactive download prompt so CI never blocks waiting
|
||||
# for confirmation.
|
||||
export COREPACK_ENABLE_DOWNLOAD_PROMPT=0
|
||||
|
||||
corepack pnpm install --frozen-lockfile
|
||||
corepack pnpm build
|
||||
|
||||
echo "Final build files:"
|
||||
find dist/
|
||||
@@ -28,6 +28,12 @@ export COREPACK_ENABLE_DOWNLOAD_PROMPT=0
|
||||
corepack pnpm install --frozen-lockfile
|
||||
corepack pnpm build
|
||||
|
||||
# Netlify's routing rules live at the app root instead of public/, because the
|
||||
# Cloudflare build must not upload them: Workers reject the `/* /index.html 200`
|
||||
# SPA fallback as a loop and cannot proxy external hosts from _redirects.
|
||||
echo "Copying Netlify _redirects into dist"
|
||||
cp _redirects dist/_redirects
|
||||
|
||||
echo "Final build files:"
|
||||
find dist/
|
||||
|
||||
|
||||
@@ -28,5 +28,9 @@
|
||||
"noFallthroughCasesInSwitch": true,
|
||||
"noUncheckedSideEffectImports": true
|
||||
},
|
||||
"include": ["src"]
|
||||
"include": ["src"],
|
||||
// Specs are not part of the app bundle and this app has no test runner of its
|
||||
// own; without this they only type-check when the parent workspace happens to
|
||||
// be installed (which the standalone Cloudflare build does not do).
|
||||
"exclude": ["src/**/*.spec.ts", "src/**/*.spec.tsx"]
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
{
|
||||
// Static-assets Worker for dashboard.artcraft.team. The only server-side code
|
||||
// is the same-origin /api proxy in cloudflare_worker/index.ts; everything else
|
||||
// is served from dist/. Build and deploy from the repository root with
|
||||
// ARTCRAFT_APP=artcraft-dashboard (see script/website/cloudflare_app.sh).
|
||||
"name": "artcraft-dashboard",
|
||||
"main": "./cloudflare_worker/index.ts",
|
||||
"compatibility_date": "2026-11-17",
|
||||
"assets": {
|
||||
"directory": "./dist",
|
||||
"binding": "ASSETS",
|
||||
// React Router owns every path that is not a file in dist/.
|
||||
"not_found_handling": "single-page-application",
|
||||
// Everything except API calls is a static file; only /api needs the Worker.
|
||||
"run_worker_first": ["/api/*"]
|
||||
},
|
||||
"routes": [
|
||||
{
|
||||
"pattern": "dashboard.artcraft.team",
|
||||
"custom_domain": true
|
||||
}
|
||||
]
|
||||
}
|
||||
+3
-1
@@ -6,6 +6,8 @@
|
||||
"deploy": "bash script/website/cloudflare_app.sh deploy",
|
||||
"build:website": "ARTCRAFT_APP=artcraft-website bash script/website/cloudflare_app.sh build",
|
||||
"build:webapp": "ARTCRAFT_APP=artcraft-webapp bash script/website/cloudflare_app.sh build",
|
||||
"deploy:webapp": "ARTCRAFT_APP=artcraft-webapp bash script/website/cloudflare_app.sh deploy"
|
||||
"deploy:webapp": "ARTCRAFT_APP=artcraft-webapp bash script/website/cloudflare_app.sh deploy",
|
||||
"build:dashboard": "ARTCRAFT_APP=artcraft-dashboard bash script/website/cloudflare_app.sh build",
|
||||
"deploy:dashboard": "ARTCRAFT_APP=artcraft-dashboard bash script/website/cloudflare_app.sh deploy"
|
||||
}
|
||||
}
|
||||
@@ -10,6 +10,7 @@
|
||||
#
|
||||
# artcraft-website (default) getartcraft.com, root wrangler.jsonc
|
||||
# artcraft-webapp app.getartcraft.com, frontend/apps/artcraft-webapp/wrangler.jsonc
|
||||
# artcraft-dashboard dashboard.artcraft.team, frontend/apps/artcraft-dashboard/wrangler.jsonc
|
||||
#
|
||||
# The webapp never builds artcraft-website-next, so it needs none of the website's
|
||||
# build secrets (LAUNCHER_CATALOG_SIGNING_KEY, and the optional LINUX_SIGNING_KEY).
|
||||
@@ -36,8 +37,16 @@ case "${APP}:${ACTION}" in
|
||||
artcraft-webapp:deploy)
|
||||
npx --yes wrangler@4 deploy --config frontend/apps/artcraft-webapp/wrangler.jsonc
|
||||
;;
|
||||
artcraft-dashboard:build)
|
||||
# Standalone pnpm app outside the Nx/npm workspace; the script installs and
|
||||
# builds inside its own folder.
|
||||
bash frontend/apps/artcraft-dashboard/script/build_cloudflare.sh
|
||||
;;
|
||||
artcraft-dashboard:deploy)
|
||||
npx --yes wrangler@4 deploy --config frontend/apps/artcraft-dashboard/wrangler.jsonc
|
||||
;;
|
||||
*)
|
||||
echo "Usage: ARTCRAFT_APP=<artcraft-website|artcraft-webapp> $0 <build|deploy>" >&2
|
||||
echo "Usage: ARTCRAFT_APP=<artcraft-website|artcraft-webapp|artcraft-dashboard> $0 <build|deploy>" >&2
|
||||
echo "Got ARTCRAFT_APP='${APP}', action='${ACTION}'." >&2
|
||||
exit 1
|
||||
;;
|
||||
|
||||
Reference in new issue
Block a user