Introduction
I have a university-managed server, that does not give students access to open ports for internet traffic, but students could still open ports (like 4040 for their NodeJS applications for internal access).
Each student's account has a public_html
folder (similar to /var/www/
), which serves all files in public_html
on this URL (using an Apache server) statically (or rendered by PHP):
http://mi-linux.wlv.ac.uk/~studentid/
Problem
However, in my case, I want to expose an API for external testing using postman and adding it to a React application. The problem is, it uses NodeJS and express, and creates its own server on port 4040
.
I could access the API by using the curl command from ssh internally like:
studentid@csl-student:~$ curl http://localhost:4040
{"message": "Hey! The backend is working. Explore routes from the code"}
Now, since students cannot allow open posts for HTTP traffic, one could simply not access my NodeJS API from outside the server (which I have to).
Things I looked up
I searched extensively on topics like how to statically serve a nodejs application, to how to forward ports from 8080 (https port) to 4040 (my NodeJS port), but most of them require sudo access, and some of them simply don't work.
Solution I propose
I think I still could access my public_html
folder, that is statically served, and could render PHP
. I know that I could create a index.html
(or index.php
) file that would fetch http://localhost:4040
internally, and simply forward the result, since the API port is open internally, and the index.html
file could be served externally.
What the file could do
While loading the file using
http://mi-linux.wlv.ac.uk/~studentid/index.html
The file could load the response from localhost:4040
internally on the server itself (since the API is accessible internally), then send the result along with the status codes and headers.
However, my API has several routes, and I could not manage to hard code each route. There must be a more efficient way of doing this.
What I'm looking for
I would be really thankful if one could direct me to a package already made for the purpose of forwarding static files with responses pre-loaded from an internal API.
Or I could have a php
script that could do all the forwarding that I need and make the API public.
PS: I know this should be asked on Server Fault, but since I think this could be done by using a script or something, I asked it here.