we can serve our static files (like a frontend app) over http with a simple command in PM2 :
pm2 serve <path> <port>
How i can serve static files with SSL using the same command pm2 serve
? is it possible ?
Or any alternatives using PM2 ?
we can serve our static files (like a frontend app) over http with a simple command in PM2 :
pm2 serve <path> <port>
How i can serve static files with SSL using the same command pm2 serve
? is it possible ?
Or any alternatives using PM2 ?
A workaround to serve a static site with HTTPS using PM2 is to add serve as a dependency to your project, then create a npm script to run serve, and have PM2 run that script instead of serving your site directly.
So, for example:
Add serve
to your project:
npm -i serve
Add a script to your package.json
, where 'build' is your build directory, and '8080' is the port you want to serve on:
"scripts": {
"serve-build": "serve -l 8080 -s build --ssl-cert 'path_to/your_certificate.crt' --ssl-key 'path_to/your_key.key'"
},
Then instead of calling pm2 serve <path> <port>
, you would instead tell PM2 to run npm and point at your script:
pm2 start npm --name your-pm2-process-name -- run serve-build
This will make PM2 run your script, which in turn runs serve
which supports https when certificates are supplied. The process will then run in the same manner as if PM2 were serving the static site itself.
© 2022 - 2024 — McMap. All rights reserved.