-
Notifications
You must be signed in to change notification settings - Fork 48
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Nuxt server/api files not found #221
Comments
Hey @EntertainmentPortal, thanks for contributing and providing the above details! I find it odd that Nuxt gets confused about which API to query, I don't think it overlaps there 🤔 How are you hosting your website? Maybe Nuxt API ( Otherwise, would you be able to provide a minimal reproduction? Else I'm happy to have a deeper look at your project if you can grant me access to it/share a zip. |
Hey @lihbr, thank you for the quick reply. The project's hosted on Vercel. I don't think /api/getSpel isn't hosted, because other functions in that folder that are loaded from the store work fine. I've added you into the project. Thanks! |
Thanks! I'll try to have a look by the end of the day |
OK, I had a look at your codebase, thanks for granting me access, I couldn't find anything odd 🤔 Could you double-check if your environment variables are correctly set on Vercel perhaps? |
@lihbr All 6 env are there as they should. This is not the problem. When checking the network tab I learned that Prismic is initiating the call to the api file. (see tab 'initiator') While Prismic shouldn't have anything to do with this file, as it is set in a Vue lifecycle hook. It appears Prismic's interfering with the call after all. |
Oh, OK! I'm pretty sure that's unrelated, the toolbar does augment the global With that, I believe the issue might be related to something else than Prismic? Maybe we can try confirming that by disabling the Prismic toolbar/preview temporarily by setting Trying to think of other things to check for: are you able to see any logs from your function being called on Vercel to try to understand what's going on there? Weirdly, it returns a 404 but according to your code it never throws nor returns so I believe it should be an empty 200 upon success(?) |
I'll check in a minute. The preview: false is already there for a while, as it was causing build errors in Vercel. |
OK my bad, to disable the toolbar also use |
Hmm, still the same result. I also tried disabling the csurf, but this didn't do anything, still 404. I see that Vercel is not logging anything, regardless the page I visit. You would say we could expect at least the 404 there, wouldn't we? |
From my understanding, the 404 is weird because according to your code no 404 could be the result of your handler for My guess is that this endpoint is not available in your production environment somehow. Since the But yeah, I don't understand why your Nuxt server endpoint is not behaving as in development in Production 🤔 Any chance you could try with your Nitro preset set to |
Setting the preset (and change NPM run generate to NPM run build) did indeed solve the problem... It somehow makes sense assuming serverless functions aren't supported, but still funny that fetching (to another file but in the same folder) from the store did work. Gonna click-around to see if I encounter any other problems now, but for now the problem seems te be solved. Thank you for your patience, help and quick responses! Appreciate it! |
You welcome, I'll close the issue for now but feel free to reopen it if anything! |
Reproduction
Additional Details
nuxt.config:
package.json:
Steps to reproduce
Followed the install documentation on prismic with the Nuxt preset.
I have several functions inside
/server/api
. Some of them are fetched from inside the store. These are some of the involved files:store/index.js:
Others are fetched from the frontend (pages or components):
pages/event.vue:
What is Expected?
In production, it should fetch data from both Prismic API as from server/api. Prismic API is used to load page data, server/api is used for some functions. Both folders are named 'api', but the foldercontent may differ. Both should be able to work.
What is actually happening?
On localhost, I don't experience any issues. But in production, I get a 404 on
api/getSpel
. My guess is that it is trying to look for this file from the Prismic API, while it should look inside the server/api folder. Probably a clash because both use/api/**
, but again, that is just my guess. Funny detail: it appears that the fetch from the store (index.js) works just fine, but any fetch from the pages / components returns 404.The text was updated successfully, but these errors were encountered: