Skip to content

Commit

Permalink
chore(pong): pass anonymous ip on click request
Browse files Browse the repository at this point in the history
  • Loading branch information
caugner committed Dec 14, 2023
1 parent 7b79d32 commit b5102d8
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
2 changes: 1 addition & 1 deletion cloud-function/src/handlers/proxy-bsa.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export async function proxyBSA(req: Request, res: Response) {
}
const params = new URLSearchParams(search);
try {
const { status, location } = await handleClick(params);
const { status, location } = await handleClick(params, countryCode);
if (location && (status === 301 || status === 302)) {
return res.redirect(location);
} else {
Expand Down
3 changes: 2 additions & 1 deletion libs/pong/pong2.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ export function createPong2GetHandler(
}>;

export function createPong2ClickHandler(coder: Coder): (
params: URLSearchParams
params: URLSearchParams,
countryCode: string
) => Promise<{
status: number;
location: string;
Expand Down
11 changes: 9 additions & 2 deletions libs/pong/pong2.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,13 +114,20 @@ export function createPong2GetHandler(zoneKeys, coder) {
}

export function createPong2ClickHandler(coder) {
return async (params) => {
return async (params, countryCode) => {
const click = coder.decodeAndVerify(params.get("code"));

if (!click) {
return {};
}
const res = await fetch(`https:${click}`, { redirect: "manual" });

const anonymousIp = anonymousIpByCC(countryCode);
const clickURL = new URL(click);
clickURL.searchParams.set("forwardedip", anonymousIp);

const res = await fetch(`https:${clickURL.toString()}`, {
redirect: "manual",
});
const status = res.status;
const location = res.headers.get("location");
return { status, location };
Expand Down

0 comments on commit b5102d8

Please sign in to comment.