fix(stats): proxy build assets under stats path
This commit is contained in:
39
packages/console/app/src/lib/stats-proxy.ts
Normal file
39
packages/console/app/src/lib/stats-proxy.ts
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
import type { APIEvent } from "@solidjs/start/server"
|
||||||
|
import { Resource } from "@opencode-ai/console-resource"
|
||||||
|
|
||||||
|
export async function statsProxy(evt: APIEvent) {
|
||||||
|
const req = evt.request.clone()
|
||||||
|
const targetUrl = new URL(req.url)
|
||||||
|
targetUrl.protocol = "https:"
|
||||||
|
targetUrl.hostname = Resource.App.stage === "production" ? "stats.opencode.ai" : "stats.dev.opencode.ai"
|
||||||
|
targetUrl.port = ""
|
||||||
|
|
||||||
|
if (targetUrl.pathname.startsWith("/stats/_build/")) {
|
||||||
|
targetUrl.pathname = targetUrl.pathname.slice("/stats".length)
|
||||||
|
}
|
||||||
|
|
||||||
|
const response = await fetch(targetUrl, {
|
||||||
|
method: req.method,
|
||||||
|
headers: req.headers,
|
||||||
|
body: req.body,
|
||||||
|
})
|
||||||
|
|
||||||
|
if (!response.headers.get("content-type")?.includes("text/html")) return response
|
||||||
|
|
||||||
|
const headers = new Headers(response.headers)
|
||||||
|
headers.delete("content-encoding")
|
||||||
|
headers.delete("content-length")
|
||||||
|
headers.delete("etag")
|
||||||
|
|
||||||
|
return new Response(rewriteStatsHtml(await response.text()), {
|
||||||
|
status: response.status,
|
||||||
|
statusText: response.statusText,
|
||||||
|
headers,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
function rewriteStatsHtml(html: string) {
|
||||||
|
return html
|
||||||
|
.replaceAll("\"/_build/", "\"/stats/_build/")
|
||||||
|
.replaceAll("'/_build/", "'/stats/_build/")
|
||||||
|
}
|
||||||
@@ -1,22 +1,8 @@
|
|||||||
import type { APIEvent } from "@solidjs/start/server"
|
import { statsProxy } from "~/lib/stats-proxy"
|
||||||
import { Resource } from "@opencode-ai/console-resource"
|
|
||||||
|
|
||||||
async function handler(evt: APIEvent) {
|
export const GET = statsProxy
|
||||||
const req = evt.request.clone()
|
export const POST = statsProxy
|
||||||
const url = new URL(req.url)
|
export const PUT = statsProxy
|
||||||
const host = Resource.App.stage === "production" ? "stats.opencode.ai" : "stats.dev.opencode.ai"
|
export const DELETE = statsProxy
|
||||||
const targetUrl = `https://${host}${url.pathname}${url.search}`
|
export const OPTIONS = statsProxy
|
||||||
|
export const PATCH = statsProxy
|
||||||
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
|
|
||||||
|
|||||||
@@ -1,22 +1,8 @@
|
|||||||
import type { APIEvent } from "@solidjs/start/server"
|
import { statsProxy } from "~/lib/stats-proxy"
|
||||||
import { Resource } from "@opencode-ai/console-resource"
|
|
||||||
|
|
||||||
async function handler(evt: APIEvent) {
|
export const GET = statsProxy
|
||||||
const req = evt.request.clone()
|
export const POST = statsProxy
|
||||||
const url = new URL(req.url)
|
export const PUT = statsProxy
|
||||||
const host = Resource.App.stage === "production" ? "stats.opencode.ai" : "stats.dev.opencode.ai"
|
export const DELETE = statsProxy
|
||||||
const targetUrl = `https://${host}${url.pathname}${url.search}`
|
export const OPTIONS = statsProxy
|
||||||
|
export const PATCH = statsProxy
|
||||||
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
|
|
||||||
|
|||||||
Reference in New Issue
Block a user