chore: stats -> data
This commit is contained in:
+1
-1
@@ -165,7 +165,7 @@ export const app = new sst.cloudflare.x.SolidStart("Stats", {
|
|||||||
domain: `stats.${domain}`,
|
domain: `stats.${domain}`,
|
||||||
link: [database, EMAILOCTOPUS_API_KEY],
|
link: [database, EMAILOCTOPUS_API_KEY],
|
||||||
environment: {
|
environment: {
|
||||||
PUBLIC_URL: `https://${domain}/stats`,
|
PUBLIC_URL: `https://${domain}/data`,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
import type { APIEvent } from "@solidjs/start/server"
|
import type { APIEvent } from "@solidjs/start/server"
|
||||||
import { Resource } from "@opencode-ai/console-resource"
|
import { Resource } from "@opencode-ai/console-resource"
|
||||||
|
|
||||||
|
const dataPath = "/data"
|
||||||
|
|
||||||
export async function statsProxy(evt: APIEvent) {
|
export async function statsProxy(evt: APIEvent) {
|
||||||
const req = evt.request.clone()
|
const req = evt.request.clone()
|
||||||
const targetUrl = new URL(req.url)
|
const targetUrl = new URL(req.url)
|
||||||
@@ -8,8 +10,8 @@ export async function statsProxy(evt: APIEvent) {
|
|||||||
targetUrl.hostname = Resource.App.stage === "production" ? "stats.opencode.ai" : "stats.dev.opencode.ai"
|
targetUrl.hostname = Resource.App.stage === "production" ? "stats.opencode.ai" : "stats.dev.opencode.ai"
|
||||||
targetUrl.port = ""
|
targetUrl.port = ""
|
||||||
|
|
||||||
if (targetUrl.pathname.startsWith("/stats/_build/") || targetUrl.pathname === "/stats/banner.png") {
|
if (targetUrl.pathname.startsWith(`${dataPath}/_build/`) || targetUrl.pathname === `${dataPath}/banner.png`) {
|
||||||
targetUrl.pathname = targetUrl.pathname.slice("/stats".length)
|
targetUrl.pathname = targetUrl.pathname.slice(dataPath.length)
|
||||||
}
|
}
|
||||||
|
|
||||||
const response = await fetch(targetUrl, {
|
const response = await fetch(targetUrl, {
|
||||||
@@ -32,6 +34,17 @@ export async function statsProxy(evt: APIEvent) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
function rewriteStatsHtml(html: string) {
|
export function statsRedirect(evt: APIEvent) {
|
||||||
return html.replaceAll('"/_build/', '"/stats/_build/').replaceAll("'/_build/", "'/stats/_build/")
|
const url = new URL(evt.request.url)
|
||||||
|
url.pathname = `${dataPath}${url.pathname.slice("/stats".length)}`
|
||||||
|
return new Response(null, {
|
||||||
|
status: 308,
|
||||||
|
headers: {
|
||||||
|
Location: url.toString(),
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
function rewriteStatsHtml(html: string) {
|
||||||
|
return html.replaceAll('"/_build/', `"${dataPath}/_build/`).replaceAll("'/_build/", `'${dataPath}/_build/`)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,8 @@
|
|||||||
|
import { statsProxy } from "~/lib/stats-proxy"
|
||||||
|
|
||||||
|
export const GET = statsProxy
|
||||||
|
export const POST = statsProxy
|
||||||
|
export const PUT = statsProxy
|
||||||
|
export const DELETE = statsProxy
|
||||||
|
export const OPTIONS = statsProxy
|
||||||
|
export const PATCH = statsProxy
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
import { statsProxy } from "~/lib/stats-proxy"
|
||||||
|
|
||||||
|
export const GET = statsProxy
|
||||||
|
export const POST = statsProxy
|
||||||
|
export const PUT = statsProxy
|
||||||
|
export const DELETE = statsProxy
|
||||||
|
export const OPTIONS = statsProxy
|
||||||
|
export const PATCH = statsProxy
|
||||||
@@ -1,8 +1,8 @@
|
|||||||
import { statsProxy } from "~/lib/stats-proxy"
|
import { statsRedirect } from "~/lib/stats-proxy"
|
||||||
|
|
||||||
export const GET = statsProxy
|
export const GET = statsRedirect
|
||||||
export const POST = statsProxy
|
export const POST = statsRedirect
|
||||||
export const PUT = statsProxy
|
export const PUT = statsRedirect
|
||||||
export const DELETE = statsProxy
|
export const DELETE = statsRedirect
|
||||||
export const OPTIONS = statsProxy
|
export const OPTIONS = statsRedirect
|
||||||
export const PATCH = statsProxy
|
export const PATCH = statsRedirect
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
import { statsProxy } from "~/lib/stats-proxy"
|
import { statsRedirect } from "~/lib/stats-proxy"
|
||||||
|
|
||||||
export const GET = statsProxy
|
export const GET = statsRedirect
|
||||||
export const POST = statsProxy
|
export const POST = statsRedirect
|
||||||
export const PUT = statsProxy
|
export const PUT = statsRedirect
|
||||||
export const DELETE = statsProxy
|
export const DELETE = statsRedirect
|
||||||
export const OPTIONS = statsProxy
|
export const OPTIONS = statsRedirect
|
||||||
export const PATCH = statsProxy
|
export const PATCH = statsRedirect
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ const rangeLabels: Record<UsageRange, string> = {
|
|||||||
}
|
}
|
||||||
const statsHomeTitle = "OpenCode Stats"
|
const statsHomeTitle = "OpenCode Stats"
|
||||||
const statsHomeDescription = "OpenCode usage, market share, token cost, and session cost stats."
|
const statsHomeDescription = "OpenCode usage, market share, token cost, and session cost stats."
|
||||||
const statsHomeFallbackUrl = "https://opencode.ai/stats/"
|
const statsHomeFallbackUrl = "https://opencode.ai/data/"
|
||||||
const statsUnfurlPath = "banner.png"
|
const statsUnfurlPath = "banner.png"
|
||||||
const statsUnfurlAlt = "OpenCode Stats wordmark on a dark patterned background"
|
const statsUnfurlAlt = "OpenCode Stats wordmark on a dark patterned background"
|
||||||
const usageColors = [
|
const usageColors = [
|
||||||
@@ -184,8 +184,8 @@ export default function StatsHome() {
|
|||||||
|
|
||||||
function getStatsHomeUrl(base: string, requestUrl: string) {
|
function getStatsHomeUrl(base: string, requestUrl: string) {
|
||||||
const url = new URL(base, requestUrl)
|
const url = new URL(base, requestUrl)
|
||||||
if (url.hostname === "stats.opencode.ai") return "https://opencode.ai/stats/"
|
if (url.hostname === "stats.opencode.ai") return "https://opencode.ai/data/"
|
||||||
if (url.hostname === "stats.dev.opencode.ai") return "https://dev.opencode.ai/stats/"
|
if (url.hostname === "stats.dev.opencode.ai") return "https://dev.opencode.ai/data/"
|
||||||
return url.toString()
|
return url.toString()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import { nitro } from "nitro/vite"
|
|||||||
import { defineConfig, type PluginOption } from "vite"
|
import { defineConfig, type PluginOption } from "vite"
|
||||||
|
|
||||||
export default defineConfig({
|
export default defineConfig({
|
||||||
base: "/stats/",
|
base: "/data/",
|
||||||
plugins: [
|
plugins: [
|
||||||
solidStart() as PluginOption,
|
solidStart() as PluginOption,
|
||||||
nitro({
|
nitro({
|
||||||
|
|||||||
Reference in New Issue
Block a user