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
Related
I created a react App which talks to a node back-end. Everything works fine in development mode. The connection between the front-end and back-end is made through websocket.
Most interesting thing is, that after doing yarn build to create the production build of the app, all the pages work fine. The only thing is that, the page that integrates connection with the back-end is returning error when I inspected it in the browser. I am using Apache Server to run the build version of the app on localhost.
I am using Apache server since python server throws errors on page refresh.
Below is the screenshot. As you can see, node server command, return the expected response from the backend app. The structure of the app is also shown; revealing the relationship between the front-end (smartschool and smartresult) and back-end (smartapi). Only the smartresult makes the request to back-end. How do I resolve this connection problem? Any help will be appreciated. Thank you.
I am developing a postman like application with some added features. For the frontend, I am using Angular 10, and for the backend, I am using node with fastify.js and for the database, I am using MongoDB via Atlassian MongoDB hosting.
Right now, I have set-up the electron app and using the same frontend code. It's working fine if I use the API(I have hosted my node server on ec2). I want to run this app without an internet connection. for that, I set up the node server in electron. The node server is working fine if I run it in the main electron process.
My electron application setup:
I am running a node server in the electron app on port 5000.
when electron app starts it will start the server.
To make sure everything is working fine I used a postman to access the node server running from the electron process.
In postman, if I am hitting on http://localhost:5000/ while the electron app is running I am getting a response from the node server running in the electron.
If I use localhost:5000 as the base URL and hit the API from frontend in electron it's working and I am getting a response. I checked the electron console network tab, Request is going to the http://localhost:5000/.
Now I want this app to run without the Internet. neDB is the most suggested DB for electron and it provides the same query syntax as MongoDB. Also, I found out library mongoose-nedb. Using that library I can use mongoose with neDB. So, If I use that library I don't need to change my node code and can use mongoose with neDB instead of MongoDB. So, I set-up my app with neDB and mongoose-neDB. for testing, I again use the postman as well as electron frontend. But now I am not getting any response.
I tried LinvoDB as well. same result.
Is this happening because I am using neDB outside the electron browser context?
Can you suggest some solution so that I don't need to rewrite the node server in the electron app?
Is this approach proper? any suggestion?
Ref:
I am using this boilerplate for the electron app: https://github.com/maximegris/angular-electron (I am putting my node code in root and importing it in main.ts)
mongoose-neDB: https://github.com/aerys/mongoose-nedb
neDB: https://github.com/louischatriot/nedb
LinvoDB: https://github.com/aerys/linvodb3
mongoose-LinvoDB: https://github.com/aerys/mongoose-linvodb3
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 an ndoejs/express app, which serves an angular6 application. Inside my angular6 app Im making http calls to my restAPI. If I host the App on localhost its working an connecting to my API.
But if i push the App to my VPS, the API call is also made to my local maschine. Is there a way to let the Angular App make the call to the VPS maschines running nodejs API? I would not like to change url everywhere in the app...
Im using Sequelize to connect to the databse etc.
Thanks.
You can add different environment files, that will hold specific settings for that environment. Have a look at this article.
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