-
Notifications
You must be signed in to change notification settings - Fork 0
feat: Plan 9 PR A — dashboard shell + CP static serve #26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| /** | ||
| * Dashboard SPA static mount (no DB required). | ||
| */ | ||
| process.env.API_KEY_HMAC_SECRET ||= 'test-hmac-secret-for-unit'; | ||
|
|
||
| import { describe, it, before, after } from 'node:test'; | ||
| import assert from 'node:assert/strict'; | ||
| import { mkdtemp, writeFile, rm } from 'node:fs/promises'; | ||
| import { tmpdir } from 'node:os'; | ||
| import path from 'node:path'; | ||
| import { createServer, type Server } from 'node:http'; | ||
| import type { Express } from 'express'; | ||
|
|
||
| describe('dashboard SPA serve', () => { | ||
| let distDir: string; | ||
| let server: Server; | ||
| let baseUrl: string; | ||
|
|
||
| before(async () => { | ||
| distDir = await mkdtemp(path.join(tmpdir(), 'verilink-dash-')); | ||
| await writeFile( | ||
| path.join(distDir, 'index.html'), | ||
| '<!doctype html><html><body><div id="root">VeriLink SPA</div></body></html>\n', | ||
| 'utf8' | ||
| ); | ||
| await writeFile(path.join(distDir, 'asset.txt'), 'static-ok\n', 'utf8'); | ||
| process.env.DASHBOARD_DIST_PATH = distDir; | ||
|
|
||
| const { createApp } = await import('../app.js'); | ||
| const app: Express = createApp(); | ||
| server = createServer(app); | ||
| await new Promise<void>((resolve, reject) => { | ||
| server.once('error', reject); | ||
| server.listen(0, '127.0.0.1', () => resolve()); | ||
| }); | ||
| const addr = server.address(); | ||
| const port = typeof addr === 'object' && addr ? addr.port : 0; | ||
| baseUrl = `http://127.0.0.1:${port}`; | ||
| }); | ||
|
|
||
| after(async () => { | ||
| await new Promise<void>((resolve, reject) => { | ||
| server.close((err) => (err ? reject(err) : resolve())); | ||
| }); | ||
| await rm(distDir, { recursive: true, force: true }); | ||
| delete process.env.DASHBOARD_DIST_PATH; | ||
| }); | ||
|
|
||
| it('serves index.html for SPA paths', async () => { | ||
| const res = await fetch(`${baseUrl}/provider`); | ||
| assert.equal(res.status, 200); | ||
| const html = await res.text(); | ||
| assert.match(html, /VeriLink SPA/); | ||
| }); | ||
|
|
||
| it('serves static assets from dist', async () => { | ||
| const res = await fetch(`${baseUrl}/asset.txt`); | ||
| assert.equal(res.status, 200); | ||
| assert.equal((await res.text()).trim(), 'static-ok'); | ||
| }); | ||
|
|
||
| it('keeps /healthz as JSON', async () => { | ||
| const res = await fetch(`${baseUrl}/healthz`); | ||
| assert.equal(res.status, 200); | ||
| const body = (await res.json()) as { ok: boolean }; | ||
| assert.equal(body.ok, true); | ||
| }); | ||
|
|
||
| it('keeps unknown /v1 routes as API 404 JSON', async () => { | ||
| const res = await fetch(`${baseUrl}/v1/does-not-exist`); | ||
| assert.equal(res.status, 404); | ||
| const body = (await res.json()) as { ok?: boolean }; | ||
| assert.notEqual(body.ok, true); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| import fs from 'node:fs'; | ||
| import path from 'node:path'; | ||
| import type { Express, NextFunction, Request, Response } from 'express'; | ||
| import express from 'express'; | ||
| import { config } from '../config.js'; | ||
| import { logger } from '../shared/logger.js'; | ||
|
|
||
| /** Resolve dashboard dist directory; empty string means "do not mount". */ | ||
| export function resolveDashboardDistPath(): string { | ||
| // Prefer live env so tests can set DASHBOARD_DIST_PATH after config freeze. | ||
| const fromEnv = (process.env.DASHBOARD_DIST_PATH || config.dashboard.distPath || '').trim(); | ||
| if (fromEnv) return path.resolve(fromEnv); | ||
| return path.resolve(process.cwd(), '../dashboard/dist'); | ||
|
coderabbitai[bot] marked this conversation as resolved.
Outdated
|
||
| } | ||
|
|
||
| function isSpaBypassPath(reqPath: string): boolean { | ||
| return ( | ||
| reqPath === '/healthz' || | ||
| reqPath.startsWith('/v1/') || | ||
| reqPath.startsWith('/webhooks/') | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
| ); | ||
|
qodo-code-review[bot] marked this conversation as resolved.
Outdated
|
||
| } | ||
|
|
||
| /** | ||
| * Serve the Vite dashboard build (static assets + SPA fallback). | ||
| * Must be mounted after API routes; never shadows /v1, /webhooks, /healthz. | ||
| * No-ops when index.html is missing (local CP without a dashboard build). | ||
| */ | ||
| export function mountDashboardSpa(app: Express): void { | ||
| const dist = resolveDashboardDistPath(); | ||
| const indexHtml = path.join(dist, 'index.html'); | ||
| if (!fs.existsSync(indexHtml)) { | ||
| logger.info({ dist }, 'dashboard dist not found; SPA not mounted'); | ||
| return; | ||
| } | ||
|
|
||
| app.use( | ||
| express.static(dist, { | ||
| index: false, | ||
| fallthrough: true, | ||
| // Hashed assets can be cached; HTML stays no-store via earlier middleware. | ||
| maxAge: '1h', | ||
| }) | ||
| ); | ||
|
|
||
| app.use((req: Request, res: Response, next: NextFunction) => { | ||
| if (req.method !== 'GET' && req.method !== 'HEAD') { | ||
| next(); | ||
| return; | ||
| } | ||
| if (isSpaBypassPath(req.path)) { | ||
| next(); | ||
| return; | ||
| } | ||
| res.sendFile(indexHtml, (err) => { | ||
| if (err) next(err); | ||
| }); | ||
| }); | ||
|
|
||
| logger.info({ dist }, 'dashboard SPA mounted'); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| # VeriLink Dashboard | ||
|
|
||
| Vite + React SPA for provider, agent-builder, and admin views (Plan 9). | ||
|
|
||
| ## Dev | ||
|
|
||
| ```bash | ||
| # Terminal 1 — control plane | ||
| cd control-plane && npm run dev | ||
|
|
||
| # Terminal 2 — dashboard (proxies /v1 to CP) | ||
| cd dashboard && npm install && npm run dev | ||
|
coderabbitai[bot] marked this conversation as resolved.
Outdated
|
||
| ``` | ||
|
|
||
| Env (`.env.local`): | ||
|
|
||
| | Variable | Notes | | ||
| |----------|--------| | ||
| | `VITE_API_BASE_URL` | Empty in dev (use Vite proxy). Absolute CP origin in production builds if not same-origin. | | ||
| | `VITE_AUTH_MODE` | `apikey` (CI/local) or `oidc` (Clerk PKCE — production). | | ||
| | `VITE_OIDC_ISSUER_URL` / `VITE_OIDC_CLIENT_ID` | Required when `oidc`. | | ||
| | `VITE_DEV_PROXY_TARGET` | Default `http://127.0.0.1:3000`. | | ||
|
|
||
| ## Production | ||
|
|
||
| ```bash | ||
| cd dashboard && npm ci && npm run build | ||
| # Serve via control plane: | ||
| DASHBOARD_DIST_PATH=/absolute/path/to/dashboard/dist npm start # in control-plane | ||
| ``` | ||
|
|
||
| Default resolve: `control-plane` looks for `../dashboard/dist` relative to cwd when `DASHBOARD_DIST_PATH` is unset. | ||
|
|
||
| ## Auth | ||
|
|
||
| - **apikey:** paste a `vrl_` key; stored in `sessionStorage`; sent as `Authorization: Bearer`. | ||
| - **oidc:** Authorization Code + PKCE against Clerk generic OIDC (no Clerk session SDK). | ||
| - Active tenant: `X-Tenant-Id` on all API calls (selector in shell). | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| <!doctype html> | ||
| <html lang="en"> | ||
| <head> | ||
| <meta charset="UTF-8" /> | ||
| <meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
| <title>VeriLink</title> | ||
| </head> | ||
| <body> | ||
| <div id="root"></div> | ||
| <script type="module" src="/src/main.tsx"></script> | ||
| </body> | ||
| </html> |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.