I already know that there is a simple command to serve static folder by PM2:
pm2 serve <path> <port>
But how can I add 404 redirection to it? e.g. redirect to 404.html
while that happends. Can't find that on Google & PM2 doc.
By default, pm2
displays 404.html from the serving directory if it can't map a request to any static file of that directory. For example, assume that your static file directory name is foo, which contains three images - 1.jpg
, 2.jpg
, 3.jpg
. You are serving those files using:
pm2 serve <path_of_foo> 8080
Now, if the server receives any request like http://localhost:8080/bar.jpg
, pm2
will look for a file named 404.html
on foo directory and display its contents, as bar.jpg
does not exist. If it doesn't find any, it show a simple text message 404 Not Found. There is no options to make it configurable (CLI or JSON), as per my knowledge.
However, if you make this file path configurable, you can take a look at here and customize the source according to your need.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With