API does not work when deployed on netlify
First of all I want to say that I am very poor at English ! : (
When I npm run dev on localhost, my functions work normally and can interact with mongoDB. I noticed that the files in my /server/api folder are not working when deploying my project on netlify. Please help me!
16 Replies
i added environment variable
seems like an issue that was addressed here
https://discord.com/channels/473401852243869706/1225087322106757172
Hey! What i did is:
- prefix the env var in netlify and the nuxt.config.ts with NUXT_PRIVATE or NUXT_PUBLIC . So NUXT_PRIVATE_dnName.
- in the nuxt.config you’ll add a private or public property object. In your case it is used in the server I would say private.
- when you use the composable do config.private.dbName
Indeed check my help post for more info.
Btw maybe you should not share your db connection string 🤪
Also make sure your mongodb allows the netlify ip adres
Thank you for the reminder, I have changed my password ^^
How can I do this?
1. Navigate to Network Access: Log in to your MongoDB Atlas account and go to the “Network Access” tab in the left-hand menu.
2. Add IP Address: Click on the “Add IP Address” button to create a new entry for allowing access.
3. Configure Access: In the modal that appears, you’ll see options for configuring access. Instead of specifying a specific IP address or CIDR block, you can choose to allow access from anywhere by selecting the “Allow access from anywhere” option.
4. Confirm Configuration: Review the settings and click “Confirm” or “Add IP Address” to save the changes.
I just allowed all ip-adresses for now. I’ll have to check later how to find the netlify ip
My api still works normally, the reason is that mongoDB has not allowed netlify access.
Thanks you very muchhhh
Should be possible in the windows cmd with the command nslookup yourdomain.com
Haven’t tried it yet
So should I only allow netlify access instead from everywhere?
I think so
But you can allow everywhere because it is locked behind a account
But best practice is to ip lock it
Nvm just allow all hahah
it's really difficult for newbies like me. Maybe I'll learn more about this later.
Np you are on the right track! Let me know if it works
yes, thank you very much ^^