NodeJS App

#1
Hello,

I'm new to OpenLiteSpeed and just about setting up my first app with it.
I have an HTTP and a HTTPS Listener. HTTPS is forced, which means I have a redirect from HTTP to HTTPS:
Code:
rewriteCond %{HTTPS} !on
rewriteRule ^(.*)$ https://%{SERVER_NAME}%{REQUEST_URI} [R,L]
I have a NodeJS app as my API server. I have followed internet instructions to set it up with my OLS server.
Bildschirmfoto 2019-02-11 um 09.54.31.png

From what I understand the /api route should now be available and forward all requests to the nodejs server. What I don't understand is: Does OLS now start the nodeJS server itself? Automatically? When? On every OLS start? And how is it supposed to know the port I configured my nodejs http server to run?

After all, it does not work. And I can also not see the port running in any process after a restart.

Help is much appreciated! Thank you :)
 
#3
Hello verflext,

Yes, OpenLiteSpeed will manage NodeJs after it is setup. It will not use the nodejs http server, it handles that all by itself. It will read the development or production config that you have setup for the NodeJS application and depends on your runtime mode which one it will read. You will not see it run on any other port as it will run on 80/443.

Are there any errors that you can see? Do you have a production config setup to use domain.tld/api/ ?
 
#4
Hello verflext,

Yes, OpenLiteSpeed will manage NodeJs after it is setup. It will not use the nodejs http server, it handles that all by itself. It will read the development or production config that you have setup for the NodeJS application and depends on your runtime mode which one it will read. You will not see it run on any other port as it will run on 80/443.

Are there any errors that you can see? Do you have a production config setup to use domain.tld/api/ ?
Thanks for your answer at first. I'm glad receiving support that fast.

Phew, I'm feeling really like a noob reading this. I don't understand... How would that work, like even technically, that OLS handles the NodeJS requests by itself?
I have no config or whatsoever. My nodeJS app is very simple. It only consists of one "route". Therefore I am also not using express. It's really just:
JavaScript:
http.createServer((req, res) => {
    // a bunch of code
});
Maybe a rewrite rule from /api to port 8080 would be the right thing to do in this case? But I would need to keep the SSL on every request.

I have a set the log level to INFO now and will keep a look on it.
 
#6
Requesting my-domain.tld/api
I'm getting an endless loading page and this in my logs:
Code:
2019-02-11 19:11:24.922722 [INFO] [x.xxx.xxx.xx:40006:HTTP2-1] [REWRITE] Rule: Match '/api' with pattern '^(.*)$', result: 2
2019-02-11 19:11:24.922778 [INFO] [x.xxx.xxx.xx:40006:HTTP2-1] [REWRITE] Cond: Match 'on' with pattern 'on', result: 1
2019-02-11 19:11:24.941062 [INFO] [x.xxx.xxx.xx:40006:HTTP2-3] [REWRITE] Rule: Match '/api/' with pattern '^(.*)$', result: 2
2019-02-11 19:11:24.941103 [INFO] [x.xxx.xxx.xx:40006:HTTP2-3] [REWRITE] Cond: Match 'on' with pattern 'on', result: 1
2019-02-11 19:11:24.941208 [INFO] [x.xxx.xxx.xx:40006:HTTP2-3] [REWRITE] Rule: Match '/api/src/index.js' with pattern '^(.*)$', result: 2
2019-02-11 19:11:24.941232 [INFO] [x.xxx.xxx.xx:40006:HTTP2-3] [REWRITE] Cond: Match 'on' with pattern 'on', result: 1
Is it good that it is saying "/api/src/index.js"? Because I do not have a directory named "api".
 
#8
Same (page never loads), but different logging:

Code:
2019-02-11 20:09:32.368933 [INFO] [x.xxx.xxx.xx:29633:HTTP2-1] [REWRITE] Rule: Match '/api/' with pattern '^(.*)$', result: 2
2019-02-11 20:09:32.368987 [INFO] [x.xxx.xxx.xx:29633:HTTP2-1] [REWRITE] Cond: Match 'on' with pattern 'on', result: 1
2019-02-11 20:09:32.369138 [INFO] [x.xxx.xxx.xx:29633:HTTP2-1] [REWRITE] Rule: Match '/api/src/index.js' with pattern '^(.*)$', result: 2
2019-02-11 20:09:32.369152 [INFO] [x.xxx.xxx.xx:29633:HTTP2-1] [REWRITE] Cond: Match 'on' with pattern 'on', result: 1
GET /api/ HTTP/1.1
host: my.domain.tld
upgrade-insecure-requests: 1
user-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.96 Safari/537.36
accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8
accept-encoding: gzip             
accept-language: de-DE,de;q=0.9,en-US;q=0.8,en;q=0.7
X-Forwarded-Host: my.domain.tld
X-Forwarded-Proto: https
X-Forwarded-For: x.xxx.xxx.xx
 
#10
Can you check the stderr.log file to see if it has any different messages?
I checked that yesterday (didn't knew it existed). I don't remember very well what it said, but it couldn't find the directory (double slash at some point) and somewhere it said something about a permission problem. However I fixed it by removed the ending slash in the settings and then I also moved the directory inside my $VH_ROOT (before I had it in a directory under /root/). Then I deleted the stderr.log (in /usr/local/lsws/logs) and restarted the server. I'm still getting a 404 on https://my.domain.tld/api. The stderr.log file exists but is always empty.

I can only show you the error.log on an /api request:
Code:
2019-02-12 17:10:29.215419 [INFO] [x.xxx.xxx.xx:12263:HTTP2-1] [REWRITE] Rule: Match '/api/' with pattern '^(.*)$', result: 2
2019-02-12 17:10:29.215478 [INFO] [x.xxx.xxx.xx:12263:HTTP2-1] [REWRITE] Cond: Match 'on' with pattern 'on', result: 1
Sorry, I really wished I could do more but I really don't know where to look.

EDIT: Wait! I came across something...
 
Last edited:
#14
@Pong Hmm... I don't know, I got some weird things going on. I might create another thread for that problem. I have implemented log4js file logging now. And it does not work on the server (I have log messages at the very beginning of the script). Even after restarting the server multiple times. When starting the server by myself with the node command, it logs.
 
Top