Specifying a method for a worker route

Hello! I am using workers to run a specific script for a specific method at a given route (for example website.com/specific-route). In order to to this I currently run this check in the worker:
if (request.method !== "POST") {
return Response.json("", { status: 405 });
}
if (request.method !== "POST") {
return Response.json("", { status: 405 });
}
However I am worried that even when called with a GET for example, this will still count as a worker invokation for billing purposes. Is there a way to restrict a worker route for a specific method?
2 Replies
Chaika
Chaika2mo ago
Best you could do is use a Custom Rule to block non-POST Requests (filter on method) when using the worker on a custom domain It's $0.30 per million requests though, ~333+ million requests for $100 dollars (excluding cpu time, but would be very tiny if the first thing it does is check that and return), even assuming ddos protection/etc doesn't kick in, Workers are pretty cheap
LabbedRat
LabbedRatOP5w ago
Hi @Chaika , Thanks a lot for the explanation! It's very clear and I greatly appreciate it!

Did you find this page helpful?