context
I've a running app on Openshift using a nodejs (nodejs-0.10). I would like to add a ngix as first proxy to serve static files only.
problem
The question is how to add nginx to a running app on Openshift. I saw this cartridge gsterjov/openshift-nginx-cartridge but the README instructs how to create a new app using the nginx, but not how to add it to an existing app.
You can not add a secondary web framework cartridge to an application. Each application can only have one web framework cartridge installed at a time. You might need to setup a second application and setup nginx as a proxy if you want the requests to hit that first and serve static assets, then proxy the dynamic requests back to your node.js application.
Related
I deployed an angular app hosted in apache server into an VPS. And I got an URL
something
like this :
http://myip.com/angularApp/
In same VPS is running pm2 with a REST api developed in nodejs using express (CORS are
enabled).
Route for these are like:
http://myip.com:4000/api/users,
http://myip.com:4001/api/clients
Problem is, when angularApp tries to consume the REST api, the URLs are =>
http://myip.com/api/users,
http://myip.com/api/clients
fyi:
I also tried to do the same in nginx but it not worked too.
Works fine in: Running static angular files in express. Running angular in dev mode
only consuming rest api.
Any idea for solving this? ty
Currently, I am developing an application that makes use of a fully dockerised Node API service (which is served locally by Docker Nginx) and a simple React front-end which is served locally using PHP valet.
Running docker-compose up, builds the dockerized application successfully hosted on Nginx on port 80 and proxy passes requests to the node API on port 9999.
The problem that I am having is getting the react front-end to communicate with the dockerised node API.
Ideally I would like to either; move the dockerized Node api service to be served by PHP valet or move the front-end webapp to also be served by the docker nginx service
How can I fully dockerize the front-end and back-end services together so that they can talk to each other (ideally both hosted on port 80) or alternatively suggest how I can use Valet or MAMP together with containerised Node API.
How can I fully dockerize the front-end and back-end services together so that they can talk to each other (ideally both hosted on port 80) or alternatively suggest how I can use Valet or MAMP together with containerised node API.
With or without Docker, you will be confronted to same origin policy for frontend requests to the backend (XMLHttpRequest and some other requests) since two URLs have the same origin if the protocol, port and host are the same.
If the two apps were containers, hosts would differ by design since these will be two distinct containers. And if you kept the frontend app on the host, it would be also the case.
So in any case, you should enable CORS in the backend side (NodeJS) for at least requests of the frontend host. From the frontend side, nothing should be needed since CORS is a browser stuff : it sends pre-flights requests to the target host to get resource sharing agreement.
About make the frontend a Docker container, I think that if the frontend is designed to work with the Node backend, you should probably also make that a docker image/container and use docker-compose to manage them : it will make them more simple to manage/maintain.
Build the front-end to static HTML and serve it from the backend from the static directory.
The React front-end is loaded on a user's machine and executes there in their browser. It communicates to the server over HTTP(S).
How are you serving the React app now? A React app is just plain text files that are served over HTTP.
Actually i have a server where there is hosted a website written in ASPX so it use IIS to run.
Now i would add an API that will permise to add some data to server database, the API is written in Node.JS so i was wondering if it's possible to run simultaneously Node and IIS.
Node is listening on port 3000 and obviously if i simply try to run 'websitedomain.it:3000/data' it doesn't work..
If something like this is possible how could i implement it?
Of course, you could run IIS and Node.JS simultaneously.
When you host webform website in IIS, it will not prevent node.js application being accessed.
You could self-host your node.js application then use URL rewrite rule and ARR to rewrite websitedomain.it:3000/data to your node.js api.
https://dev.to/petereysermans/hosting-a-node-js-application-on-windows-with-iis-as-reverse-proxy-397b
Of course, you could host your nodejs application in IIS with iisnode extension directly.
https://github.com/tjanczuk/iisnode/releases
I have react app and nodejs api server. React app make fetch requests to nodejs server. React app and nodejs server deployed in own containers.
The problem is I can access nodejs server directly in browser, so is there way to 'hide' nodejs backend server, and let access only through frontend.
It should work something like this
React app make fetch request
nginx intercept request and forward to nodejs server
nodejs handles request
I think it can be done with nginx reverse proxy or docker networks or somehow...
yes there is. What you do is run a docker-compose that runs 3 docker containers. One container runs nginx, the second one runs create-react-app host ui, and the 3rd one runs a node js api. You then set the nginx routing rule for all /api/* routes to be reverse proxied to the nodejs api then you make sure all other get requests /* go to the create-react-app being hosted.
Here is a similar example on medium: https://medium.com/#xiaolishen/develop-in-docker-a-node-backend-and-a-react-front-end-talking-to-each-other-5c522156f634
I have got 2 applications:
Nodejs application and Angular application.
I would like to host them both on the same Linux server (Linode).
Also I have a DNS record for example : forexample.com.
I would like that when I navigate to api.forexample.com it will navigate inside the linux server to the Angular application, and I should see the angular pages.
The nodejs application is a API application which I would like other people to make all the HTTP requests to api.forexample.com/api.
So the question is how to make the navigation inside the linux server?
Generally speaking to run multiple applications on a server. First you need to add an A record on your DNS record for api.forexample.com
Then you can use nginx to handle the two applications. The way it will work is that each application will run locally on its own port and nginx will handle the url you provide and map it to the appropriate application. Check out this tutorial: Configure Nginx as a web server
In your situation you could serve the angular app from the node application.
Check this too: How to serve an angular2 app in a node.js server