Skip to content

Commit ebfcd90

Browse files
committed
better proxying of traces and info
1 parent 573087f commit ebfcd90

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

src/index.ts

+9-9
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ export default {
1212
return new Response(index_html(env), { headers: { 'Content-Type': 'text/html' } })
1313
} else if (pathname === '/v1/logs' && request.method === 'POST') {
1414
return await logProxy(request)
15-
} else if (pathname === '/v1/traces' && request.method === 'POST') {
16-
return await traceProxy(request)
17-
} else if (pathname === '/v1/traces' && request.method === 'OPTIONS') {
18-
return tracePreflight(request)
19-
} else if (pathname === '/v1/info') {
20-
return await fetch(`https://logfire-api.pydantic.dev${pathname}`, request)
15+
} else if (pathname.startsWith('/v1/')) {
16+
if (request.method === 'OPTIONS') {
17+
return preflight(request)
18+
} else {
19+
return await pureProxy(request, pathname)
20+
}
2121
} else {
2222
return new Response(`404: '${request.method} ${pathname}' not found`, { status: 404 })
2323
}
@@ -80,8 +80,8 @@ async function logProxy(request: Request): Promise<Response> {
8080
}
8181
}
8282

83-
async function traceProxy(request: Request): Promise<Response> {
84-
const response = await fetch('https://logfire-api.pydantic.dev/v1/traces', request)
83+
async function pureProxy(request: Request, pathname: string): Promise<Response> {
84+
const response = await fetch(`https://logfire-api.pydantic.dev${pathname}`, request)
8585
// add CORS headers
8686
return new Response(response.body, {
8787
status: response.status,
@@ -93,7 +93,7 @@ async function traceProxy(request: Request): Promise<Response> {
9393
})
9494
}
9595

96-
const tracePreflight = (request: Request) =>
96+
const preflight = (request: Request) =>
9797
new Response(null, {
9898
status: 204,
9999
headers: {

0 commit comments

Comments
 (0)