Pages function/worker alias

Is it possible to create an alias for a function/worker?

For example can I access /query? and /q? using the same function.

I’ve tried _routes.json and wrangler.toml without success.

Thank you

If you’re using Pages Functions with the standard file-based routing, the easiest thing would be to just create the alias. If you have a query.js file, create q.js, and have that file import a function from query.js and call it. You may even be able to just import and re-export the onRequest function from query.js, depending on how the code is written.

1 Like

Thanks, I’ll try that

Edit: @i40west won’t this approach count as two requests, which would be wasteful on quota?

No. I’m not suggesting making a subrequest to the other endpoint. The request would be handled by q.js which happens to import the same code.

All of the Functions files are bundled into one Worker. You can import code to your endpoint files from anywhere else in your project.

Thank you

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.