What is recommended way to set up a web server? - web

I have a server and I am designing some web applications. I use React as frontend framework and Rust Actix as backend framework. The backend program listens at 8000 port, and can be reached by my_domain:8000/api/xxxx.
I think I can use a web server listening at 80 port, such that if client is requesting /, then returning the frontend page, if client is requesting /api, then redirect the request to 8000 port of localhost.
My problems are:
Is the above way recommended in the modern web application design? Are there any other ways of hosting both frontend and backend application in the server?
What web server can I use? Apache, Nginx, or manually write a web server?
I use two docker containers to contain the frontend and backend app. Do I need to dockerize the web server as well?

Related

does socket.io server need to be seperate from backend when deploying?

I am building react app. I have my client folder, and my backend folder that contains all my mongo db models, routes, functions etc...
I know realize that my app needs to use socket.io
My frontend is on localhost:3000 and my backend is on localhost:5000
My understanding is that socket.io needs its own port.
Does this mean when I deploy to heroku I need to deploy a backend server, frontend server, and a socket.io server?
My understanding is that socket.io needs its own port.
This is incorrect. socket.io can use the same port as your backend just fine. Incoming requests to create a socket.io connection can be distinguished from other web requests via a custom header that the underlying webSocket connection protocol uses. This allows socket.io/webSocket and your http server to use the exact same port.
Does this mean when I deploy to heroku I need to deploy a backend server, frontend server, and a socket.io server?
No. You can still just have frontend server and backend server and the backend server can handle both your backend requests and the socket.io connections.

How build to deploy node app to http server

Is there any way to use express or other nodejs librarys to to design an api and deploy it pasting files as a resource path in a web server just like react.
My web server just listen on ports 80 and 443.
I have pages on domain.com/page1 domain.com/page2.
and i want to deploy an api listening on domain.com/page3 but i cant install a nodejs server and proxy requests to page3 to it.
Thanks a lot
There can be only one web server listening on a given port. You can directly "listen to a path", only a port.
So, if you already have an existing web server running on ports 80 and 443, then these are your options.
Modify your existing web server to add your API server code to it so it can handle requests for http://yourdomain.com/page3 and https://yourdomain.com/page3 directly with your API.
You can add some middleware to your existing web server to make it a proxy for http://yourdomain.com/page3 that will redirect requests to your http://yourdomain.com:3000/page3 Express-based API server.
Run your own Express-based API server on your own separate port and access the API server directly via the separate port such as http://yourdomain.com:3000/page3.
You can install a proxy such as nginx in front of your existing web server and have it redirect incoming requests to http://yourdomain.com/page3 and https://yourdomain.com/page3 to the separate port that your Express-based API server is running on.

Secure way of hosting Node.js on windows server

I need to host Node App on the Window Server using IIS. IIS provides only two ways iisnode module and reverse proxy using Application request Routing.
the problem here is that issnode is no longer being maintained by Microsoft and isn't secure to use, same as the case with reverse proxy.
What's the secure way of hosting Node.js app on Windows server?

Google Cloud Node.js Socket Server Application Hosting

I have two node js application. One of them is a webserver. It serves static html css javascript and image files. This web server is running on google cloud app engine. I have a domain that is bind to this app engine. And whenever a user visits my domain my webserver gives responses to it and it gets my frontend of my website.
The other node application is a socket server(socket io). It runs on a compute engine and i want this socket server to communicate securely. Because there are important messages for me in a communication of client and server sockets. Thats why i bought an ssl certificate.
I applied my ssl certificate to my domain and now i want my client sockets to connect to a port of my domain(for example to https://www.example.com:8443)
However i dont know how to forward 8443 port of my domain into my compute engine's 8443 port without terminating the https security.
How can i do that?
Thank you in advance
Well the Google Console has a networking section from where you can open ports for your applications. See this link: https://console.cloud.google.com/networking/firewalls/list?project={your-project-id}. Replace {your-project-id} with your project id.
Another option is that instead of using a ssl certificate, you can encrypt the messages sent between your server and client

Hosting a Web Server and Web Service locally on same port

I seem to miss somehting really obvious.
Anyways, i am developing a ReactJs web app and use nodejs (browser-sync) to host a simple web server for testing on localhost. Everything's working fine.
As for the server side i have a REST Service hosted in ASP.NET WebAPI.
I want to keep the urls in the web app relative for deployment reasons (because then it doesn't matter what the hostname is, as long it's running on the same domain).
I know out of experience that it's possible to host a self hosted ASP.NET WebAPI and a Web Application in IIS Express (at least in different paths) at the same time.
But now when i start browser-sync (which uses node http server internally as far as i can tell) and then WebAPI service host, the service host tells me it can't host on this url.
When i start it the other way around, browser-sync automatically increases the port so that it's on the next free port.
Does somebody have experience with it?
EDIT:
My question maybe in a more general sense: How do you develop web apps that are hosted on a local web server (in my case via nodejs) against a local running web service? And do you use relative URLs in your web app? Which leads to the problem that the service and the web have to run on the same server
I solved my problem like this:
ASP.NET WebAPI hosts under a different port then the nodejs web server
I set up a proxy in nodejs webserver for all urls starting with '/api/' and proxy these requests to the WebAPI port
I can use relative URLs in my client

Resources