Skip to content

Commit

Permalink
Multi-build manifests
Browse files Browse the repository at this point in the history
  • Loading branch information
zx8086 committed Jan 20, 2025
1 parent bc6fd15 commit 8ea99f3
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 22 deletions.
12 changes: 9 additions & 3 deletions src/lib/context/tracker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,12 @@ function getCurrentApmTransaction() {
}

const getIngestPoint = () => {
// Use the existing environment variables that worked before
return import.meta.env.PUBLIC_OPENREPLAY_INGEST_POINT;
const baseUrl = import.meta.env.DEV
? 'https://api.openreplay.com'
: 'https://openreplay.prd.shared-services.eu.pvh.cloud';

// Ensure we don't double the ingest path
return baseUrl;
};

const getResourceBaseHref = () => {
Expand Down Expand Up @@ -90,7 +94,9 @@ export async function initTracker() {
'traceparent': true,
'tracestate': true,
'elastic-apm-traceparent': true,
'x-openreplay-session-id': true
'x-openreplay-session-id': true,
'content-type': true,
'authorization': true
}
},
verbose: true,
Expand Down
44 changes: 25 additions & 19 deletions vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,32 +80,38 @@ export default defineConfig(({ mode }): UserConfig => {
timeout: 5000
},
proxy: {
'^/ingest/v1/web/': {
'/ingest/v1/web/': {
target: import.meta.env.DEV
? 'https://api.openreplay.com'
: 'https://openreplay.prd.shared-services.eu.pvh.cloud',
changeOrigin: true,
secure: true,
rewrite: (path) => path,
ws: true,
rewrite: (path) => path.replace(/^\/ingest/, ''),
configure: (proxy, _options) => {
proxy.on('proxyReq', (proxyReq, req, _res) => {
try {
// Set specific headers for OpenReplay
proxyReq.setHeader('Access-Control-Allow-Origin', '*');
proxyReq.setHeader('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE, OPTIONS');
proxyReq.setHeader('Access-Control-Allow-Headers', 'Content-Type, Authorization, traceparent, tracestate, elastic-apm-traceparent, x-openreplay-session-id');
proxyReq.setHeader('Access-Control-Expose-Headers', '*');

// Copy original headers
if (req.headers) {
Object.keys(req.headers).forEach(key => {
if (key.toLowerCase() !== 'host') {
proxyReq.setHeader(key, req.headers[key]);
}
});
}
} catch (error) {
console.error('Error in proxy request:', error);
proxyReq.setHeader('Access-Control-Allow-Origin', '*');
proxyReq.setHeader('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE, OPTIONS');
proxyReq.setHeader('Access-Control-Allow-Headers', 'Content-Type, Authorization, traceparent, tracestate, elastic-apm-traceparent, x-openreplay-session-id');
proxyReq.setHeader('Access-Control-Max-Age', '3600');
proxyReq.setHeader('Access-Control-Expose-Headers', '*');

if (req.headers) {
Object.keys(req.headers).forEach(key => {
if (key.toLowerCase() !== 'host') {
proxyReq.setHeader(key, req.headers[key]);
}
});
}
});

proxy.on('proxyRes', (proxyRes, req, res) => {
if (req.method === 'OPTIONS') {
proxyRes.headers['Access-Control-Allow-Origin'] = '*';
proxyRes.headers['Access-Control-Allow-Methods'] = 'GET, POST, PUT, DELETE, OPTIONS';
proxyRes.headers['Access-Control-Allow-Headers'] = 'Content-Type, Authorization, traceparent, tracestate, elastic-apm-traceparent, x-openreplay-session-id';
proxyRes.headers['Access-Control-Max-Age'] = '3600';
proxyRes.headers['Access-Control-Expose-Headers'] = '*';
}
});
}
Expand Down

0 comments on commit 8ea99f3

Please sign in to comment.