I published my site on Netlify except that to access the API data I receive:
Failed to load resource: the server responded with a status of 404 ()and to display certain images:Failed to load resource: the server responded with a status of 404 ().``` and index-DNQVcT_m.js:48 Error fetching clean data: AxiosError.
Hi, @Essama-Official. You cannot run server side code at Netlify outside of functions or edge functions. This site has no functions or edge functions deployed.
How are you deploying that code? Are you bundling it into a serverless function? If so, how? If not, that is a requirement so that is why it isn’t working.
well in quick config I initialized the start of the url: target: ‘https://orbis-api-web.azurewebsites.net’, and then I do the rest with '/api/v1/Activities/all and locally it works
The settings you’ve used apply to Vite dev server. I thought you had your API server on Netlify throwing this issue. This issue doesn’t have anything to do with Netlify. When you build your app, Vite server doesn’t run, thus your Vite config would not work there.
You should make a request directly to your endpoint without relying on Vite’s config. Or configure proxy in Netlify: Redirects and rewrites | Netlify Docs
Hi, @Essama-Official. That URL is a 404 because no such page exists in the deploy and there is no redirect configured for that path.
What did you try to do here? Did you try to create a redirect? If so, what steps did you take? If you didn’t try to create a redirect, what were you trying?
Hi, I’m going to start again, I removed the url from vite.congig and now I receive: Access to XMLHttpRequest at has been blocked by CORS policy: No ‘Access-Control-Allow-Origin’ header is present on the requested resource .
I tried npm install cors and app.use with cors but it doesn’t change anything
No redirects are processed for your project because:
You have incorrectly named the file _redirects.txt instead of _redirects.
The file is not in the public directory as is required for static assets you need/want included in a Vite build. Read more: Static Asset Handling | Vite
The activities page is calling an API hosted on Azure. It is on this API endpoint the required CORS headers (including Access-Control-Allow-Origin) need setting to permit the front-end on Netlify to make the request successfully. Read more about CORS: Cross-Origin Resource Sharing (CORS) - HTTP | MDN
There is no need to include the node_modules directory in the git repository. These modules are downloaded and installed by Netlify during the build process (ditto for other platforms.)