repositories
loading repo index
repositories
loading repo index
repository
loading code, commits, and activity
public Clawd ADK gateway launch mirror
stars
latest
clone command
git clone gitlawb://did:key:z6Mkq5mY...iFZ5/my-project-publ...git clone gitlawb://did:key:z6Mkq5mY.../my-project-publ...2fa351d6docs: add automaton and perps launch sources16d ago| #1 | import { Hono } from 'hono'; |
| #2 | import type { AppEnv } from '../types'; |
| #3 | import { MOLTBOT_PORT } from '../config'; |
| #4 | import { findExistingMoltbotProcess } from '../gateway'; |
| #5 | |
| #6 | /** |
| #7 | * Public routes - NO Cloudflare Access authentication required |
| #8 | * |
| #9 | * These routes are mounted BEFORE the auth middleware is applied. |
| #10 | * Includes: health checks, static assets, and public API endpoints. |
| #11 | */ |
| #12 | const publicRoutes = new Hono<AppEnv>(); |
| #13 | |
| #14 | // GET /sandbox-health - Health check endpoint |
| #15 | publicRoutes.get('/sandbox-health', (c) => { |
| #16 | return c.json({ |
| #17 | status: 'ok', |
| #18 | service: 'moltbot-sandbox', |
| #19 | gateway_port: MOLTBOT_PORT, |
| #20 | }); |
| #21 | }); |
| #22 | |
| #23 | // GET /logo.png - Serve logo from ASSETS binding |
| #24 | publicRoutes.get('/logo.png', (c) => { |
| #25 | return c.env.ASSETS.fetch(c.req.raw); |
| #26 | }); |
| #27 | |
| #28 | // GET /logo-small.png - Serve small logo from ASSETS binding |
| #29 | publicRoutes.get('/logo-small.png', (c) => { |
| #30 | return c.env.ASSETS.fetch(c.req.raw); |
| #31 | }); |
| #32 | |
| #33 | // GET /api/status - Public health check for gateway status (no auth required) |
| #34 | publicRoutes.get('/api/status', async (c) => { |
| #35 | const sandbox = c.get('sandbox'); |
| #36 | |
| #37 | try { |
| #38 | const process = await findExistingMoltbotProcess(sandbox); |
| #39 | if (!process) { |
| #40 | return c.json({ ok: false, status: 'not_running' }); |
| #41 | } |
| #42 | |
| #43 | // Process exists, check if it's actually responding |
| #44 | // Try to reach the gateway with a short timeout |
| #45 | try { |
| #46 | await process.waitForPort(18789, { mode: 'tcp', timeout: 5000 }); |
| #47 | return c.json({ ok: true, status: 'running', processId: process.id }); |
| #48 | } catch { |
| #49 | return c.json({ ok: false, status: 'not_responding', processId: process.id }); |
| #50 | } |
| #51 | } catch (err) { |
| #52 | return c.json({ ok: false, status: 'error', error: err instanceof Error ? err.message : 'Unknown error' }); |
| #53 | } |
| #54 | }); |
| #55 | |
| #56 | // GET /_admin/assets/* - Admin UI static assets (CSS, JS need to load for login redirect) |
| #57 | // Assets are built to dist/client with base "/_admin/" |
| #58 | publicRoutes.get('/_admin/assets/*', async (c) => { |
| #59 | const url = new URL(c.req.url); |
| #60 | // Rewrite /_admin/assets/* to /assets/* for the ASSETS binding |
| #61 | const assetPath = url.pathname.replace('/_admin/assets/', '/assets/'); |
| #62 | const assetUrl = new URL(assetPath, url.origin); |
| #63 | return c.env.ASSETS.fetch(new Request(assetUrl.toString(), c.req.raw)); |
| #64 | }); |
| #65 | |
| #66 | export { publicRoutes }; |
| #67 |