Score:1

Best way to serve static folder that is not presented in frontend build

jm flag

I have the following situation. Web content of my app is located in a standard directory /var/www/my.domain.com/html/. Also I have a folder users_statics somewhere inside this directory, where my app stores some essential files that were uploaded by users. Note, that these files are not incorporated in frontend build, and during usage only URLs to this files are needed.

However, my deploy pipeline script deletes all files inside the /var/www/my.domain.com/html/ and inserts new frontend build, which by default doesn't contain user_statics directory. For example:

rm -rf /var/www/my.domain.com/html/*
cp -av build/. /var/www/my.domain.com/html/

So I am obliged to store user_statics directory in some other location and after every deployment rsync it to the web content folder:

  mkdir /var/www/my.domain.com/html/.../user_statics
  rsync -qah ./user-statics-bkp/* /var/www/my.domain.com/html/.../user_statics

I am not sure this is the most desirable way to deal with this folder, since by this time I want to add API to the backend app to interact with its contents. Thus, for example I can run into the incorrect API calls to this folder during deployment process.

I see the following options but none of them seems to me perfect:

  1. Somehow rewrite CD pipeline to "ignore" this folder during the deployment.
  2. Move this folder to the /var/www/html/ folder and write additional directives to nginx config file.
  3. Open subdomain for this folder and create server block for this subdomain. However, I am not sure if this one folder "deserves" to be separated to the new server block.

From your experience are there any better ways to correctly deal with it?

Score:0
jm flag

Finally I placed this folder in this path /var/www/html/path/to/user_statics and added simple location directive to the sites-available/my.domain.com nginx config file:

location /path/to/user_statics {
     root /var/www/html/;
}

So after that nginx proxies user_statics requests to this place in server file system, separate from /var/www/my.domain.com/html/. By this moment this solution works for me well.

I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.