i wrap my head around an error, which does not look logic for me. The problem did not exist on localhost testing environment, but unfortunately on prod environment:
I run nodeJS on Docker behind a proxy. All of the APIS from node working fine. However on frontend iam requesting a image, which returns always an 404 on path:
https://my-domain.de/img/1722676874813
The number 1722676874813 points on a compressed image, which is stored as an upload from node js just fine in the /img dir. As mentioned, on localhost this works like a charm. The /img is living inside the root directory, where index.js is located as well. I have added to my express config:
const storage = multer.diskStorage({
destination: (reg, file, cb) => {
cb(null, '/usr/src/app/img')
},
filename: (reg, file, cb) => {
cb(null, Date.now() + path.extname(file.originalname))
}
})
const upload = multer({ storage: storage });
app.use(express.static('img')); //serve static img files
the multer config with given path works fine. After a file upload i do find the file inside the docker /img as well as in the mounted drive /distBackend/img.
exec into docker shows, that these folder is available and the file also. File structure at /usr/src/app in docker looks like this:
config controller img index.js models node_modules package-lock.json package.json server.log websocket.server.js
The corresponding docker image for backend looks like following:
backend:
image: node:latest
container_name: nodeJSBackend
command: node /usr/src/app/index.js
volumes:
- ./distBackend:/usr/src/app
networks:
- default
- proxy
labels:
- traefik.enable=true
- traefik.http.routers.backend.rule=Host(`backend.my-domain.de`) && ( PathPrefix(`/registerNewPlayer`) || PathPrefix(`/login`) )
- traefik.http.routers.backend.tls=true
- traefik.http.routers.backend.tls.certresolver=lets-encrypt
- traefik.http.services.backend.loadbalancer.server.port=8080
networks:
proxy:
external: true
The /distBackend is a volume, which contains an /img file as well as the build files. Right now i would need a hint, where the error might be. Thank you very much in advance, Regards Marc
I have changed the app.use(express.static('img'));
to app.use(express.static('/usr/src/app/img'));
. That did not work. Docker logs dont show any error. Iam not sure if Traefik rule might block the request. But in this case i should see a 500 error, not a 404.