chore: stats -> data
This commit is contained in:
parent
7c1e61af1e
commit
b4a6419215
8 changed files with 51 additions and 22 deletions
|
|
@ -1,6 +1,8 @@
|
|||
import type { APIEvent } from "@solidjs/start/server"
|
||||
import { Resource } from "@opencode-ai/console-resource"
|
||||
|
||||
const dataPath = "/data"
|
||||
|
||||
export async function statsProxy(evt: APIEvent) {
|
||||
const req = evt.request.clone()
|
||||
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.port = ""
|
||||
|
||||
if (targetUrl.pathname.startsWith("/stats/_build/") || targetUrl.pathname === "/stats/banner.png") {
|
||||
targetUrl.pathname = targetUrl.pathname.slice("/stats".length)
|
||||
if (targetUrl.pathname.startsWith(`${dataPath}/_build/`) || targetUrl.pathname === `${dataPath}/banner.png`) {
|
||||
targetUrl.pathname = targetUrl.pathname.slice(dataPath.length)
|
||||
}
|
||||
|
||||
const response = await fetch(targetUrl, {
|
||||
|
|
@ -32,6 +34,17 @@ export async function statsProxy(evt: APIEvent) {
|
|||
})
|
||||
}
|
||||
|
||||
function rewriteStatsHtml(html: string) {
|
||||
return html.replaceAll('"/_build/', '"/stats/_build/').replaceAll("'/_build/", "'/stats/_build/")
|
||||
export function statsRedirect(evt: APIEvent) {
|
||||
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/`)
|
||||
}
|
||||
|
|
|
|||
8
packages/console/app/src/routes/data/[...path].ts
Normal file
8
packages/console/app/src/routes/data/[...path].ts
Normal file
|
|
@ -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
|
||||
8
packages/console/app/src/routes/data/index.ts
Normal file
8
packages/console/app/src/routes/data/index.ts
Normal file
|
|
@ -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 POST = statsProxy
|
||||
export const PUT = statsProxy
|
||||
export const DELETE = statsProxy
|
||||
export const OPTIONS = statsProxy
|
||||
export const PATCH = statsProxy
|
||||
export const GET = statsRedirect
|
||||
export const POST = statsRedirect
|
||||
export const PUT = statsRedirect
|
||||
export const DELETE = statsRedirect
|
||||
export const OPTIONS = statsRedirect
|
||||
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 POST = statsProxy
|
||||
export const PUT = statsProxy
|
||||
export const DELETE = statsProxy
|
||||
export const OPTIONS = statsProxy
|
||||
export const PATCH = statsProxy
|
||||
export const GET = statsRedirect
|
||||
export const POST = statsRedirect
|
||||
export const PUT = statsRedirect
|
||||
export const DELETE = statsRedirect
|
||||
export const OPTIONS = statsRedirect
|
||||
export const PATCH = statsRedirect
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue