GeezerVison is showing github.com — feat(stats): route stats app · flcs/opencode@58da1ea
File treeExpand file treeCollapse file tree Open diff view settings console/app/src/routes/stats
Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: infra/stats.ts +10-9Lines changed: 10 additions & 9 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 1 | 1 | import { lakeAthenaWorkgroup, lakeCatalog, lakeCluster, lakeQueryPermissions, lakeRegion, tableBucket } from "./lake" | | 2 | +import { EMAILOCTOPUS_API_KEY } from "./app" | 2 | 3 |
| 3 | 4 | const domain = (() => { | 4 | 5 | if ($app.stage === "production") return "stats.opencode.ai" | @@ -163,15 +164,15 @@ new sst.x.DevCommand("StatsStudio", { | 163 | 164 | // APP | 164 | 165 | //////////////// | 165 | 166 |
| 166 | | -// export const app = new sst.cloudflare.x.SolidStart("Stats", { | 167 | | -// path: "packages/stats/app", | 168 | | -// buildCommand: "bun run build", | 169 | | -// domain, | 170 | | -// link: [database], | 171 | | -// environment: { | 172 | | -// PUBLIC_URL: `https://${domain}`, | 173 | | -// }, | 174 | | -// }) | | 167 | +export const app = new sst.cloudflare.x.SolidStart("Stats", { | | 168 | + path: "packages/stats/app", | | 169 | + buildCommand: "bun run build", | | 170 | + domain, | | 171 | + link: [database, EMAILOCTOPUS_API_KEY], | | 172 | + environment: { | | 173 | + PUBLIC_URL: `https://${domain}/stats`, | | 174 | + }, | | 175 | +}) | 175 | 176 |
| 176 | 177 | //////////////// | 177 | 178 | // SERVICES | |
Collapse file Copy file name to clipboard +22Lines changed: 22 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +import type { APIEvent } from "@solidjs/start/server" | | 2 | +import { Resource } from "@opencode-ai/console-resource" | | 3 | + | | 4 | +async function handler(evt: APIEvent) { | | 5 | + const req = evt.request.clone() | | 6 | + const url = new URL(req.url) | | 7 | + const host = Resource.App.stage === "production" ? "stats.opencode.ai" : "stats.dev.opencode.ai" | | 8 | + const targetUrl = `https://${host}${url.pathname}${url.search}` | | 9 | + | | 10 | + return fetch(targetUrl, { | | 11 | + method: req.method, | | 12 | + headers: req.headers, | | 13 | + body: req.body, | | 14 | + }) | | 15 | +} | | 16 | + | | 17 | +export const GET = handler | | 18 | +export const POST = handler | | 19 | +export const PUT = handler | | 20 | +export const DELETE = handler | | 21 | +export const OPTIONS = handler | | 22 | +export const PATCH = handler |
Collapse file Copy file name to clipboard +22Lines changed: 22 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +import type { APIEvent } from "@solidjs/start/server" | | 2 | +import { Resource } from "@opencode-ai/console-resource" | | 3 | + | | 4 | +async function handler(evt: APIEvent) { | | 5 | + const req = evt.request.clone() | | 6 | + const url = new URL(req.url) | | 7 | + const host = Resource.App.stage === "production" ? "stats.opencode.ai" : "stats.dev.opencode.ai" | | 8 | + const targetUrl = `https://${host}${url.pathname}${url.search}` | | 9 | + | | 10 | + return fetch(targetUrl, { | | 11 | + method: req.method, | | 12 | + headers: req.headers, | | 13 | + body: req.body, | | 14 | + }) | | 15 | +} | | 16 | + | | 17 | +export const GET = handler | | 18 | +export const POST = handler | | 19 | +export const PUT = handler | | 20 | +export const DELETE = handler | | 21 | +export const OPTIONS = handler | | 22 | +export const PATCH = handler |
Collapse file Copy file name to clipboardExpand all lines: packages/stats/app/src/app.tsx +1Lines changed: 1 addition & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -16,6 +16,7 @@ function AppMeta() { | 16 | 16 | export default function App() { | 17 | 17 | return ( | 18 | 18 | <Router | | 19 | + base={import.meta.env.BASE_URL.replace(/\/$/, "")} | 19 | 20 | explicitLinks={true} | 20 | 21 | root={(props) => ( | 21 | 22 | <MetaProvider> | |
Collapse file Copy file name to clipboardExpand all lines: packages/stats/app/src/routes/index.tsx +2-2Lines changed: 2 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -1213,7 +1213,7 @@ function Header() { | 1213 | 1213 | return ( | 1214 | 1214 | <header data-component="top" data-menu-open={menuOpen() ? "true" : undefined}> | 1215 | 1215 | <div data-slot="header-bar"> | 1216 | | - <a data-slot="brand" href="/" aria-label="OpenCode home"> | | 1216 | + <a data-slot="brand" href={import.meta.env.BASE_URL} aria-label="Stats home"> | 1217 | 1217 | <StatsWordmark /> | 1218 | 1218 | </a> | 1219 | 1219 | <nav data-component="section-nav" aria-label="Stats sections"> | @@ -1436,7 +1436,7 @@ function SubscribeModal(props: { onClose: () => void }) { | 1436 | 1436 | event.preventDefault() | 1437 | 1437 | setStatus("pending") | 1438 | 1438 | setMessage("") | 1439 | | - fetch("/api/newsletter", { | | 1439 | + fetch(`${import.meta.env.BASE_URL}api/newsletter`, { | 1440 | 1440 | method: "POST", | 1441 | 1441 | body: new FormData(event.currentTarget), | 1442 | 1442 | }).then( | |
Collapse file Copy file name to clipboard +1Lines changed: 1 addition & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +export { GET } from "../../api/health" |
Collapse file Copy file name to clipboard +1Lines changed: 1 addition & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +export { POST } from "../../api/newsletter" |
Collapse file Copy file name to clipboardExpand all lines: packages/stats/app/vite.config.ts +1Lines changed: 1 addition & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -3,6 +3,7 @@ import { nitro } from "nitro/vite" | 3 | 3 | import { defineConfig, type PluginOption } from "vite" | 4 | 4 |
| 5 | 5 | export default defineConfig({ | | 6 | + base: "/stats/", | 6 | 7 | plugins: [ | 7 | 8 | solidStart() as PluginOption, | 8 | 9 | nitro({ | |
Collapse file Copy file name to clipboardExpand all lines: sst.config.ts +2-5Lines changed: 2 additions & 5 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -30,10 +30,7 @@ export default $config({ | 30 | 30 | async run() { | 31 | 31 | const stage = await import("./infra/stage.js") | 32 | 32 | await import("./infra/app.js") | 33 | | - if (stage.deployAws) { | 34 | | - await import("./infra/lake.js") | 35 | | - await import("./infra/stats.js") | 36 | | - } | | 33 | + const stats = stage.deployAws ? await import("./infra/lake.js").then(() => import("./infra/stats.js")) : undefined | 37 | 34 | const { stat } = await import("./infra/console.js") | 38 | 35 | await import("./infra/enterprise.js") | 39 | 36 | if ($app.stage === "production" || $app.stage === "vimtor") { | @@ -42,7 +39,7 @@ export default $config({ | 42 | 39 |
| 43 | 40 | return { | 44 | 41 | StatWorkerUrl: stat.url, | 45 | | - // StatsUrl: stats.app.url, | | 42 | + ...(stats ? { StatsUrl: stats.app.url } : {}), | 46 | 43 | AwsStage: stage.awsStage, | 47 | 44 | } | 48 | 45 | }, | |
|