Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

change the way to fix referer header for some paths #1026

Merged
merged 3 commits into from
Feb 26, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 14 additions & 14 deletions streamshop/sections/Stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,20 +53,20 @@ export default function Stories({
</div>
</Section.Container>
<script
async
src="https://assets.streamshop.com.br/sdk-ads/liveshop-ads-video.min.js"
>
</script>
<script
async
src="https://assets.streamshop.com.br/sdk-ads/liveshop-ads-carousel.min.js"
>
</script>
<script
async
src="https://assets.streamshop.com.br/sdk/liveshop-web-sdk.min.js"
>
</script>
async
src="https://assets.streamshop.com.br/sdk-ads/liveshop-ads-video.min.js"
>
</script>
<script
async
src="https://assets.streamshop.com.br/sdk-ads/liveshop-ads-carousel.min.js"
>
</script>
<script
async
src="https://assets.streamshop.com.br/sdk/liveshop-web-sdk.min.js"
>
</script>
</>
);
}
Expand Down
20 changes: 4 additions & 16 deletions vtex/loaders/proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ const PATHS_TO_PROXY = [
"/XMLData/*",
"/_v/*",
];

export const VTEX_PATHS_THAT_REQUIRES_SAME_REFERER = ["/no-cache/AviseMe.aspx"];

const decoSiteMapUrl = "/sitemap/deco.xml";

const buildProxyRoutes = (
Expand Down Expand Up @@ -71,23 +74,8 @@ const buildProxyRoutes = (
includeScriptsToHead,
includeScriptsToBody,
removeDirtyCookies: true,
pathsThatRequireSameReferer: VTEX_PATHS_THAT_REQUIRES_SAME_REFERER,
};
// we have this check because we need to add
// the referer header to the AviseMe route
if (pathTemplate.includes("AviseMe")) {
return {
pathTemplate,
handler: {
value: {
...handlerValue,
customHeaders: [{
key: "referer",
value: urlToProxy,
}],
},
},
};
}

return ({
pathTemplate,
Expand Down
5 changes: 5 additions & 0 deletions website/handlers/proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ export interface Props {
*/
removeDirtyCookies?: boolean;
excludeHeaders?: string[];
pathsThatRequireSameReferer?: string[];
}
/**
* @title Proxy
Expand All @@ -102,6 +103,7 @@ export default function Proxy({
redirect = "manual",
replaces,
removeDirtyCookies = false,
pathsThatRequireSameReferer = [],
}: Props): Handler {
return async (req, _ctx) => {
const url = new URL(req.url);
Expand Down Expand Up @@ -147,6 +149,9 @@ export default function Proxy({
for (const key of excludeHeaders) {
headers.delete(key);
}
if (pathsThatRequireSameReferer.includes(to.pathname)) {
headers.set("referer", to.href);
}
const response = await fetch(to, {
headers,
redirect,
Expand Down
3 changes: 3 additions & 0 deletions website/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import {
type FnContext,
type Site,
} from "@deco/deco";
import { VTEX_PATHS_THAT_REQUIRES_SAME_REFERER } from "../vtex/loaders/proxy.ts";

declare global {
interface Window {
LIVE: {
Expand Down Expand Up @@ -185,6 +187,7 @@ const getAbTestAudience = (abTesting: AbTesting) => {
includeScriptsToHead: abTesting.includeScriptsToHead,
includeScriptsToBody: abTesting.includeScriptsToBody,
replaces: abTesting.replaces,
pathsThatRequireSameReferer: [...VTEX_PATHS_THAT_REQUIRES_SAME_REFERER],
},
};
if (abTesting.enabled) {
Expand Down
Loading