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!
No description
No description
No description
No description
No description
No description
16 Replies
Lâm Lybi Dash
Lâm Lybi DashOP8mo ago
i added environment variable
No description
pyplacca
pyplacca8mo ago
Luckystriike
Luckystriike8mo ago
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.
Luckystriike
Luckystriike8mo ago
No description
No description
Luckystriike
Luckystriike8mo ago
Btw maybe you should not share your db connection string 🤪 Also make sure your mongodb allows the netlify ip adres
Lâm Lybi Dash
Lâm Lybi DashOP8mo ago
Thank you for the reminder, I have changed my password ^^ How can I do this?
Luckystriike
Luckystriike8mo ago
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
Lâm Lybi Dash
Lâm Lybi DashOP8mo ago
My api still works normally, the reason is that mongoDB has not allowed netlify access. Thanks you very muchhhh
Luckystriike
Luckystriike8mo ago
Should be possible in the windows cmd with the command nslookup yourdomain.com Haven’t tried it yet
Lâm Lybi Dash
Lâm Lybi DashOP8mo ago
So should I only allow netlify access instead from everywhere?
Luckystriike
Luckystriike8mo ago
I think so But you can allow everywhere because it is locked behind a account But best practice is to ip lock it
Luckystriike
Luckystriike8mo ago
No description
Luckystriike
Luckystriike8mo ago
Nvm just allow all hahah
Lâm Lybi Dash
Lâm Lybi DashOP8mo ago
it's really difficult for newbies like me. Maybe I'll learn more about this later.
Luckystriike
Luckystriike8mo ago
Np you are on the right track! Let me know if it works
Lâm Lybi Dash
Lâm Lybi DashOP8mo ago
yes, thank you very much ^^
Want results from more Discord servers?
Add your server