Files
splatoon3.ink/workers/updater/admin/vite.config.mjs
Matt Isenhower c2666b27ca Add an admin panel to the updater Worker
A small Vue + Tailwind app in workers/updater/admin, served by the updater
Worker on its own hostname (admin.splatoon3.ink, admin.dev.splatoon3.ink)
behind Cloudflare Access:

- Timeline: both lanes, credential renewals, and social posts on one time
  axis, a filterable run list, run details with per-updater timings and
  the run's own log lines, lane controls (run now, pause, scheduling),
  credential renewal, and a combined text log.
- Social: the post log with errors, per-account posting switches, when
  each status last went to each account, and a preview that can post one
  status by hand after a confirmation.
- Data: freshness of the core data files, the published file list, a
  check that the site serves the new data, and a cache purge.

Worker side:

- src/admin: the Access JWT check (jose; fails closed and only answers on
  ADMIN_HOSTNAME) and the API. Actions must be same-origin JSON POSTs, and
  the app is served with a strict CSP from the ADMIN_ASSETS binding.
- Runs capture their console output (AsyncLocalStorage), so log lines
  belong to the run that printed them. The Scheduler keeps a post log and
  serves run details and log lines; RegionAuth keeps its last 24 renewals.
- A manual run from the panel only posts to social when asked to.

Shared code:

- StatusGeneratorManager records what was posted or failed, and skips
  accounts turned off in private settings/social.json (the Node runner
  honours this too). app/social/admin.mjs previews and posts one status.
- Updater results include their duration.

Also: npm run admin:dev runs the panel against a simulated API, deploy
scripts build the panel first, the dev environment's assets move to
dev-assets.splatoon3.ink, and the lockfile drops entries nothing depends
on any more.

Not yet run against a deployed Worker or a real Access application.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-10 12:59:36 -08:00

52 lines
1.5 KiB
JavaScript

// The admin panel is its own small Vue app, separate from the public site's bundle. It builds
// to admin/dist, which the updater Worker serves behind Cloudflare Access (see ../wrangler.jsonc).
//
// `npm run admin:dev` serves it with a simulated API (mock/api.mjs): no Worker, no credentials.
import { defineConfig } from 'vite';
import vue from '@vitejs/plugin-vue';
import tailwindcss from '@tailwindcss/vite';
import { createMockApi } from './mock/api.mjs';
function mockApi() {
return {
name: 'admin-mock-api',
apply: 'serve',
configureServer(server) {
let api = createMockApi();
server.middlewares.use('/admin/api', async (request, response) => {
let chunks = [];
for await (let chunk of request) {
chunks.push(chunk);
}
let body = null;
try {
body = chunks.length ? JSON.parse(Buffer.concat(chunks).toString()) : null;
} catch {
// Leave the body empty; the handler rejects it.
}
let url = new URL(request.url, 'http://localhost');
let result = api.handle(request.method, url.pathname, url.searchParams, body);
response.writeHead(result.status, { 'Content-Type': 'application/json', 'Cache-Control': 'no-store' });
response.end(JSON.stringify(result.body));
});
},
};
}
export default defineConfig({
root: import.meta.dirname,
plugins: [vue(), tailwindcss(), mockApi()],
server: { port: 5180, strictPort: true },
build: {
outDir: 'dist',
emptyOutDir: true,
},
});