Home > Software engineering >  Accessing images in node microservice
Accessing images in node microservice

Time:01-07

I have a backend that is composed of multiple microservices, one of them is the media microservice whose job is to receive a payload through rabbitmq and save the received files on the filesystem. The main backend then receives the response from the broker and saves the path and filename in a database. The frontend clients then receive the path and display the image found in the media microservice.

This all works fine when developing locally. But im missing a crucial part in production where i havent quite figured out how to configure nginx to allow access to the files/images. The main backend lives on a certain port and the microservices each on a different port (plan is to later dockerize the microservices and deploy them each on separate vps'). The media microservice does not have any functionality to serve any images, it just handles saving the files to the filesystem, so all i need is a way to access the files on said filesystem. Any hints on how i can configure something of the sort in nginx?

CodePudding user response:

So turns out I still needed express or at least express makes the procedure much easier to serve the actual files.

app.use("/images", express.static(path.join(__dirname   "/media/images")));

With the following nginx configuration

location /images/ {
    proxy_pass http://localhost:****;
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection 'upgrade';
    proxy_set_header Host $host;
    proxy_cache_bypass $http_upgrade;
}
  • Related