API shield endpoints with an optional prefix
I've got a setup which I feel should be quite common: an API hosted on Workers at a domain like
Now for the first time I'm setting up API Shield endpoints, for the main purpose of blocking fall-through routes against my API (blocking malicious lookups against routes that are not defined), and also getting per-route insights/stats/security recommendations.
The trouble is, on the Pro plan, the number of endpoints is limited to 250. Adding 2x endpoints for every route (e.g.
I considered running a transform rule to strip the
Are there any techniques I can use for this scenario, setting up Endpoints effectively for an API when routing has an optional prefix:
api.example.com and also routes defined as sub-paths on other domains e.g. example.com/api, othersite.example.com/api, with the sole purpose of efficiency avoiding CORS lookups. It means I strip the optional /api prefix from the URL which may or may not be there depending on which route the request came through.Now for the first time I'm setting up API Shield endpoints, for the main purpose of blocking fall-through routes against my API (blocking malicious lookups against routes that are not defined), and also getting per-route insights/stats/security recommendations.
The trouble is, on the Pro plan, the number of endpoints is limited to 250. Adding 2x endpoints for every route (e.g.
/my/route and /api/my/route) will put me over the limit, as well as diluting the aforementioned insights and stats.I considered running a transform rule to strip the
/api prefix, but transform rules run before Workers Routes rules, so it would prevent /api/* requests from being routed to the worker at all.Are there any techniques I can use for this scenario, setting up Endpoints effectively for an API when routing has an optional prefix:
api.example.com->my-workerexample.com/api/*->my-worker