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

This commit is contained in:
Adam Gastineau 2025-01-30 08:42:02 -08:00
parent 833c729eb0
commit b39cd3d535

View file

@ -67,6 +67,10 @@ export async function startTraceViewerServer(options?: TraceViewerServerOptions)
server.routePrefix('/trace', (request, response) => {
const url = new URL('http://localhost' + request.url!);
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'))
return true;
if (relativePath.startsWith('/file')) {