Skip to content

Commit

Permalink
short circuit if main
Browse files Browse the repository at this point in the history
  • Loading branch information
man-sg committed Oct 31, 2022
1 parent af31dd4 commit c69beb0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
8 changes: 4 additions & 4 deletions .netlify/state.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
{
"geolocation": {
"data": {
"city": "Abyhoj",
"city": "Ishøj",
"country": {
"code": "DK",
"name": "Denmark"
},
"subdivision": {
"code": "82",
"name": "Central Jutland"
"code": "84",
"name": "Capital Region"
}
},
"timestamp": 1666946135442
"timestamp": 1667215722359
}
}
11 changes: 8 additions & 3 deletions netlify/edge-functions/split-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ export default async (request: Request, context: any) => {
return context.next();
}

const requestUrl = new URL(request.url);

console.log("INC URLS: ", requestUrl.origin, buckets[0].url)
if (requestUrl.origin === buckets[0].url) {
return context.next();
}

//Ensure weighting adds up to 1
const totalWeighting = buckets.reduce(
(tot: any, bucket: any) => tot + bucket.weight,
Expand All @@ -17,8 +24,6 @@ export default async (request: Request, context: any) => {
//Set the cookie name of the bucket
const cookieName = "netlify-split-test";

const requestUrl = new URL(request.url);

// Get the bucket from the cookie
let bucket = context.cookies.get(cookieName);
let hasBucket = !!bucket;
Expand Down Expand Up @@ -54,7 +59,7 @@ export default async (request: Request, context: any) => {

//Generate full proxy url
const url = `${bucket}${requestUrl.pathname}`;
context.log({ url });
context.log("Proxy-URL:", { url });
//Set cookie if new bucket has been set
if (!hasBucket) {
context.cookies.delete(cookieName);
Expand Down

0 comments on commit c69beb0

Please sign in to comment.