"NetworkError when attempting to fetch resource"
When attempting to use this project after building it locally and using the .env variables, the webpage only displays "NetworkError when attempting to fetch resource".
I have this project configured to look at my local IP address of Immich and have verified the correct username and API key for the one account I am trying to use. I have even used an external URL and the webpage still shows the error message. I have even commented out the args in the compose file in hopes that the webpage asks for the URL and API as stated in Option B in the ReadMe.md, but it does no such thing.
The logs see that I am connecting to the webpage but provide no helpful information as to what's happening. I am unable to see any pictures, albums, or anything other than the error message.
Edit: A reddit post (I assume by the developer) says "It’s absolutely possible to do locally (we do it in dev) but an internal dns needs to be setup so immich api sends the correct headers (cors). This is a limitation from Immich API as far as I’m concerned. Please refer to their docs again. We use NPM for this (nginx-proxy-manager) and it works fine." However, I just tried with my internal DNS (with and without SSL) and still get the same results.
Please check https://api.immich.app/ again. You can also try without the .env file its not needed, the UI will instead show an input dialog where you can use your API Key+URL.
Try curling your immich instance from the adress of where immich-swipe is sitting:
curl -I -X OPTIONS http://<immich-instance-domain>/api/users/me -H "Origin: http://<swipe-domain>"
see if you correctly receive: Access-Control-Allow-Origin: *
if you are using NPM (nginx-proxy-manager) you will likely have to add the headers in:
<wherever-you-have-your-containers/nginx-proxy-manager/data/nginx/proxy_host/<conf_that_belongs_to_immich>.conf
Can you reach the API of your instance from somewhere else?
If you have any trouble feel free to respond here. We'd love for you to be able to use it, its awesome 🥇
You can also try without the .env file its not needed, the UI will instead show an input dialog where you can use your API Key+URL.
I stated that I did this in my original post. The UI did not show an input dialog where I could use my API Key+URL
Try curling your immich instance from the adress of where immich-swipe is sitting:
curl -I -X OPTIONS http://<immich-instance-domain>/api/users/me -H "Origin: http://<swipe-domain>"see if you correctly receive: Access-Control-Allow-Origin: *
I get the following, both from using external urls, ip+port, and my internal DNS:
HTTP/1.1 404 Not Found
Can you reach the API of your instanced from somewhere else?
Yes, I can reach the API of Immich locally and remotely with my other services. Immich-swipe is the only one that is having issues with Immich.
The root cause is that Immich doesn't respond to CORS OPTIONS preflight requests (returns 404), so any direct browser-to-Immich request from a different origin will fail with a NetworkError regardless of your setup.
The fix is to route API calls through the nginx proxy that's already built into immich-swipe at /immich-api/, which handles CORS and forwards requests to Immich internally.
Two things needed:
-
Set VITE_SERVER_URL to point at the immich-swipe container itself (not your Immich instance):
VITE_SERVER_URL=http://<your-swipe-host>:<swipe-port>/immich-apiFor example if immich-swipe runs on port 2293:http://localhost:2293/immich-api -
The default nginx.conf has a bug with newer nginx versions where the $backend variable is uninitialized (you'll see invalid URL prefix in "" in the logs). Work around it by mounting a fixed nginx config that uses a static proxy_pass instead of the variable:
Replace the /immich-api/ location block's variable logic:
Remove these lines:
resolver 8.8.8.8 127.0.0.11 valid=30s ipv6=off;
set $backend "http://immich-server:2283";
if ($http_x_target_host) {
set $backend $http_x_target_host;
}
proxy_pass $backend;
Replace with:
proxy_pass http://immich-server:2283; # or your immich service hostname
Mount the fixed config in your compose file:
volumes:
- ./fixed-nginx.conf:/etc/nginx/conf.d/default.conf:ro
This routes browser requests same-origin through nginx → Immich internally, bypassing CORS entirely.
Thanks @captainmustard - this suggestion worked for me.
Everyone thats still interested can try the new release which makes this process a little easier
Also features a new slightly enhanced UI, new settings and some little quirks.
Since demand has been picking up lately I thought I'd do everyone (including me) a favor and do a really quick pass on the app. I am still actively using the app myself.