fix(ui): add proper CORS header for loading traces in HMR mode (#34558)

This commit is contained in:
Adam Gastineau 2025-01-30 09:20:43 -08:00 committed by GitHub
parent 833c729eb0
commit 5afb04b62e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -67,6 +67,10 @@ export async function startTraceViewerServer(options?: TraceViewerServerOptions)
server.routePrefix('/trace', (request, response) => { server.routePrefix('/trace', (request, response) => {
const url = new URL('http://localhost' + request.url!); const url = new URL('http://localhost' + request.url!);
const relativePath = url.pathname.slice('/trace'.length); const relativePath = url.pathname.slice('/trace'.length);
if (process.env.PW_HMR) {
// When running in Vite HMR mode, port is hardcoded in build.js
response.appendHeader('Access-Control-Allow-Origin', 'http://localhost:44223');
}
if (relativePath.endsWith('/stall.js')) if (relativePath.endsWith('/stall.js'))
return true; return true;
if (relativePath.startsWith('/file')) { if (relativePath.startsWith('/file')) {