From 58da1ea48e85ba9f9dbf2536c404000927055349 Mon Sep 17 00:00:00 2001 From: Adam <2363879+adamdotdevin@users.noreply.github.com> Date: Thu, 28 May 2026 18:37:13 -0500 Subject: [PATCH] feat(stats): route stats app --- infra/stats.ts | 19 ++++++++-------- .../console/app/src/routes/stats/[...path].ts | 22 +++++++++++++++++++ .../console/app/src/routes/stats/index.ts | 22 +++++++++++++++++++ packages/stats/app/src/app.tsx | 1 + packages/stats/app/src/routes/index.tsx | 4 ++-- .../stats/app/src/routes/stats/api/health.ts | 1 + .../app/src/routes/stats/api/newsletter.ts | 1 + packages/stats/app/vite.config.ts | 1 + sst.config.ts | 7 ++---- 9 files changed, 62 insertions(+), 16 deletions(-) create mode 100644 packages/console/app/src/routes/stats/[...path].ts create mode 100644 packages/console/app/src/routes/stats/index.ts create mode 100644 packages/stats/app/src/routes/stats/api/health.ts create mode 100644 packages/stats/app/src/routes/stats/api/newsletter.ts diff --git a/infra/stats.ts b/infra/stats.ts index 28d50fe0e3..107e8b9f23 100644 --- a/infra/stats.ts +++ b/infra/stats.ts @@ -1,4 +1,5 @@ import { lakeAthenaWorkgroup, lakeCatalog, lakeCluster, lakeQueryPermissions, lakeRegion, tableBucket } from "./lake" +import { EMAILOCTOPUS_API_KEY } from "./app" const domain = (() => { if ($app.stage === "production") return "stats.opencode.ai" @@ -163,15 +164,15 @@ new sst.x.DevCommand("StatsStudio", { // APP //////////////// -// export const app = new sst.cloudflare.x.SolidStart("Stats", { -// path: "packages/stats/app", -// buildCommand: "bun run build", -// domain, -// link: [database], -// environment: { -// PUBLIC_URL: `https://${domain}`, -// }, -// }) +export const app = new sst.cloudflare.x.SolidStart("Stats", { + path: "packages/stats/app", + buildCommand: "bun run build", + domain, + link: [database, EMAILOCTOPUS_API_KEY], + environment: { + PUBLIC_URL: `https://${domain}/stats`, + }, +}) //////////////// // SERVICES diff --git a/packages/console/app/src/routes/stats/[...path].ts b/packages/console/app/src/routes/stats/[...path].ts new file mode 100644 index 0000000000..326ff2c117 --- /dev/null +++ b/packages/console/app/src/routes/stats/[...path].ts @@ -0,0 +1,22 @@ +import type { APIEvent } from "@solidjs/start/server" +import { Resource } from "@opencode-ai/console-resource" + +async function handler(evt: APIEvent) { + const req = evt.request.clone() + const url = new URL(req.url) + const host = Resource.App.stage === "production" ? "stats.opencode.ai" : "stats.dev.opencode.ai" + const targetUrl = `https://${host}${url.pathname}${url.search}` + + return fetch(targetUrl, { + method: req.method, + headers: req.headers, + body: req.body, + }) +} + +export const GET = handler +export const POST = handler +export const PUT = handler +export const DELETE = handler +export const OPTIONS = handler +export const PATCH = handler diff --git a/packages/console/app/src/routes/stats/index.ts b/packages/console/app/src/routes/stats/index.ts new file mode 100644 index 0000000000..326ff2c117 --- /dev/null +++ b/packages/console/app/src/routes/stats/index.ts @@ -0,0 +1,22 @@ +import type { APIEvent } from "@solidjs/start/server" +import { Resource } from "@opencode-ai/console-resource" + +async function handler(evt: APIEvent) { + const req = evt.request.clone() + const url = new URL(req.url) + const host = Resource.App.stage === "production" ? "stats.opencode.ai" : "stats.dev.opencode.ai" + const targetUrl = `https://${host}${url.pathname}${url.search}` + + return fetch(targetUrl, { + method: req.method, + headers: req.headers, + body: req.body, + }) +} + +export const GET = handler +export const POST = handler +export const PUT = handler +export const DELETE = handler +export const OPTIONS = handler +export const PATCH = handler diff --git a/packages/stats/app/src/app.tsx b/packages/stats/app/src/app.tsx index 3a356119b0..976633f295 100644 --- a/packages/stats/app/src/app.tsx +++ b/packages/stats/app/src/app.tsx @@ -16,6 +16,7 @@ function AppMeta() { export default function App() { return ( ( diff --git a/packages/stats/app/src/routes/index.tsx b/packages/stats/app/src/routes/index.tsx index 0b1a801e7c..5ee4f5f2ec 100644 --- a/packages/stats/app/src/routes/index.tsx +++ b/packages/stats/app/src/routes/index.tsx @@ -1213,7 +1213,7 @@ function Header() { return (
- +