Skip to content

Commit

Permalink
Only make fetch if type matches.
Browse files Browse the repository at this point in the history
  • Loading branch information
KristofferStrube committed Nov 28, 2023
1 parent a2c7b59 commit 0d7a245
Showing 1 changed file with 13 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -95,15 +95,19 @@ await fetchEvent.RespondWithAsync(async () =>
var json = await messageEvent.GetDataAsync();
var type = await json.GetAttributeAsStringAsync("type");
logger.WriteLine($"The message had type '{type}'!");
ReadableStreamProxy payload = await json.GetAttributeProxyAsync<ReadableStreamProxy>("payload");
await scope.FetchAsync("https://kristoffer-strube.dk/API/receive",
new RequestInit {
Method = "POST",
Body = payload,
Credentials = "omit",
Duplex = "half"
});
logger.WriteLine($"The message payload was sent to an API on the Worker Thread using fetch!");
if (type is "test")
{
ReadableStreamProxy payload = await json.GetAttributeProxyAsync<ReadableStreamProxy>("payload");
await scope.FetchAsync("https://kristoffer-strube.dk/API/receive",
new RequestInit
{
Method = "POST",
Body = payload,
Credentials = "omit",
Duplex = "half"
});
logger.WriteLine($"The message payload was sent to an API on the Worker Thread using fetch!");
}
};
logger.WriteLine("We Initialized!");
await Task.CompletedTask;
Expand Down

0 comments on commit 0d7a245

Please sign in to comment.