Skip to content

Commit

Permalink
remove missing sourcemap error (#12)
Browse files Browse the repository at this point in the history
  • Loading branch information
silesky authored Mar 22, 2023
1 parent 8c9d565 commit a79ee8b
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/four-coats-remember.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@segment/edge-sdk": major
---

Fix missing sourcemap error
23 changes: 19 additions & 4 deletions packages/edge-sdk/src/assetsProxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,21 @@ export const redactWritekey: HandlerFunction = async (
return [request, new Response(body, response), ctx];
};

// get rid of 'missing sourcemaps' error
export const removeSourcemapReference: HandlerFunction = async (
request,
response,
ctx
) => {
if (response.status !== 200) {
return [request, response, ctx];
}
const content = await response.text();
const body = content.replace(new RegExp("//#.*"), "");

return [request, new Response(body, response), ctx];
};

export const configureApiHost: HandlerFunction = async (
request,
response,
Expand All @@ -127,11 +142,11 @@ export const configureApiHost: HandlerFunction = async (

const host = ctx.host;
// rather than send to api.segment.io, configure analytics to proxy event calls through worker.
const settings = await response.json() as any
const apiHost = `${host}/${ctx.settings.routePrefix}/evs`
const settings = (await response.json()) as any;
const apiHost = `${host}/${ctx.settings.routePrefix}/evs`;
// we parse settings because of bug where apiHost is missing.
settings.integrations["Segment.io"].apiHost = apiHost
settings.metrics.host = apiHost
settings.integrations["Segment.io"].apiHost = apiHost;
settings.metrics.host = apiHost;
return [request, new Response(JSON.stringify(settings), response), ctx];
};

Expand Down
2 changes: 2 additions & 0 deletions packages/edge-sdk/src/segment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import {
handleCORS,
handleSettings,
redactWritekey,
removeSourcemapReference,
} from "./assetsProxy";
import { handleTAPI, includeEdgeTraitsInContext, injectWritekey } from "./tapi";
import {
Expand Down Expand Up @@ -175,6 +176,7 @@ export class Segment {
features.serverSideCookies || features.clientSideTraits
)
.handler(appendAJSCustomConfiguration)
.handler(removeSourcemapReference)
.handler(redactWritekey, features.redactWritekey);

// settings handlers
Expand Down

0 comments on commit a79ee8b

Please sign in to comment.