When I set up rewrites for a function that uses Express they don’t seem to work. However, when typing in the full endpoint for a function that uses express I am able to get it to work.
Below is a link to my repository on GitHub. In my client folder, you can see my redirects file with the rewrite rules I implemented. In my server folder you can see two functions I set up as examples. withexpress.js uses Express and withoutexpress.js uses the regular syntax.
Thank you for your reply! Yes, I am using express with my Netlify functions. I followed the tutorial on Netlify below to get everything set up. Everything for the functions works.
I am just having problems with rewriting the urls of the functions. I have two functions set up in my GitHub repository as examples. They both do the same thing. For the one that uses the regular syntax for functions it works, but for the one that uses Express I get an error unless I go to the full path of /.netlify/functions/api/withexpress. Additonally, setting up a 301 redirect works, bit I would really like to only show clean urls instead of the full endpoints for the functions.
Just so I make sure I understand your goal correctly: you want to use redirects to make your function “endpoint” in the browser be something like “/listOfItems” instead of “/.netlify/functions/listOfItems”?
Thank you for your reply! Yes, my goal would be to have something like “/listOfItems” instead of “/.netlify/functions/listOfItems.
Also, yes, that is my redirects file. I set it up like that to show how I am doing the same thing for both, but only the function that doesn’t use express seems to actually rewrite the function. When I change the number to 301 there isn’t any issues. It shows the full endpoint which I don’t want. Do you know why this is and how I could fix it?