In my template files, I consistently use the following code snippet:
<link href="http://localhost:3000/css/bootstrap.min.css" rel="stylesheet">
Each time I launch the website, I need to update the IP address from http://localhost:3000
to the web server's IP. With numerous template files across the site, this becomes a tedious task. To avoid this, I have developed scripts that can automatically replace the IP in the template files whenever needed.
I would prefer to maintain the format like this:
<link href="css/bootstrap.min.css" rel="stylesheet">
This way, it is not tied to a specific origin. Ideally, there should be middleware in Express that can use the server's current location to serve the files.
Currently, in my server.js
file, I am using the following code:
app.use(express.static(path.join(__dirname ,'/v1/public/')));
It works well when I specify the host in the template files. However, I have not come across any readily available resources that offer a simple solution to achieve what I'm looking for.