I'm currently running two servers, both on my local machine. One is Spring, the other is Flask. The Spring server handles major business logic of my application, whereas the Flask one handles light database access operations. Additionally, I have a React Node.js server that interacts with both of these. I am considering merging the Flask server into my Spring server to solve this problem, but I am curious to know the correct way of connecting to two servers.
I am using a React proxy to use the port of the Spring server, and I'm making my calls on that, whereas my Flask server I connect to with 'http://127.0.0.1:5000/' via fetch. This has been working great when accessing the site from the hosting PC, but when trying to access it remotely via port forwarding, the Flask server cannot be accessed. This makes sense, because React is looking at the localhost of that machine.
My question is: other than merging the two servers, how can I connect to both of them remotely like this? Is there something big I am missing? I am of course happy to provide all files or information necessary, and as this is my first time doing a project like this, I hope what I've explained is sufficient.
EDIT: Just as an aside, I think some of this is due to Flask's default behavior of not allowing outside connections. I will update this more if anything comes of my tests.
EDIT2: I tested this even more and found that the Flask server access works great when the react proxy points to it, whereas the Spring server fails. The opposite behavior I have now. So it isn't about Flask default behavior, but the fact that React can only proxy into one server at a time.
I have got this working, and a good answer was posted on SO already, just under different phrasing, so I didn't find it. I will link the post here!
Multi server solution
Specifically, I just wasn't familiar with the setupProxy.js file, and this is the solution to this problem.
Related
I've made a node.js application which hosts a webserver over http using the express framework but i'd like to upgrade to https.
However I can't seem to find a good way to do this since the application will be run on different PCs which could have different public IP addresses so pre-generating a certificate wouldn't be possible.
Furthermore if possible I'd like to keep the application as portable as possible so locally installing open-ssl or expecting it is locally installed isn't really an option unless it can be packaged with the server itself somehow.
How would one go about building what I've described above?
If anyone could give me some pointers that would be fantastic.
Use docker/kubernetes together with a reverse proxy that automatically generates SSL certificates. I can recommend Traefik.
I have two questions a bit theoretical. I searched in the Internet but I didn't get a clear answer.
My first question:
I would like to develop an app in MEAN stack (Mongo, Angular8, NodeJS server), but I don't want to have a central server connected with the database somewhere and all the clients just connect to it remotely. I want to deploy the whole app (mongo database, server back-end, angular front-end) locally in a standalone pc. Yes, the user would have to activate both database and server services and yes, he would have to use the app through the browser at the localhost address, but I don't want him to be able to see the code. Is it possible or do you have in mind any trick to achieve that?
My second question:
Can I directly link mongo database with the Angular8 code without interfere the NodeJS API's?
I know that my questions are a bit generic, but I am not looking for huge answers, rather if my questions are possible and some tips on how to move on.
For the first question: Your user will always be able to see the compiled code (through the developer console for example) but not the source code of the angular application.
I have a very basic question. When I write REST services, there is a server on which your service runs. When I write my service in Java using dropwizard framework, it uses Jetty server to expose endpoints. But what is actually this server? Because server is just a machine on which we host. For example, in node js application, when we just write a createServer(), it creates the server locally on the machine. Does it also have some fancy names like Jetty or Tomcat that it uses internally? I am little confused, what exactly is meant by Jetty, Tomcat, etc? Are these some library which makes it easy to connect to the machine OS and all or its something else.
My question looks very dumb but I wanted to understand the concept of servers.
This is a little bit confusing, you're right, as server can mean the machine itself, or the software that actually creates the web server.
But software needs some hardware to run, isn't it ?
Server usually means the combination of both.
Node.js servers have also some fancy names like Express, or Sails, and many others that make setting up your app easier.
This is more about the context of the discussion than frameworks and languages.
I'm currently learning NodeJS and pretty excited about it.
But here is one thing that I am unsure and need help about.
As we know that NodeJS has its own internal http web server and we can simply create using http.createServer() method.
My questions are:
Is the internal http web server that NodeJS has, meant to replace similar http web server like Apache or Nginx?
If I need to create enterprise-scale application, does NodeJS internal web service capable of doing this? Or do I need to still use Apache/Nginx?
Please help. Thank you.
Adrian
node.js does not require a web server the likes of Apache or nginx, it is its own web server.
Walmart has used node for, in their words, "end-to-end javascript"... that is certainly enterprise-scale, though they don't explicitly say they're relying on http.createServer, end-to-end javascript would eliminate Apache or nginx and I doubt they've developed some exotic solution (though socket.io is a possibility)... generally speaking if you're using node on the web, you're using the built in web server in at least some capacity.
There perhaps is some benefit to using nginx as a reverse-proxy/static file server on the front end. If I were designing my "perfect system" I'd probably do that, but I'd still be passing back requests to the built in web server in node.
You don't need to use Apache or Nginx with node.js, but in practice, its probably a good idea.
Basically, Apache would sit in front of your node.js, and relay requests to and from your node app, using something like mod_rewrite.
The node http server module is great for firing up quick applications, but if you need things like SSL, complex mod_rewrites, directory security, detailed logs etc (ie all the stuff you would need in a commercial application), you need (or at least, its easier) to use Apache or Nginx in front of node.
Ok so finally decided I was way behind in knowing some of the frameworks/platforms that are out like Angularjs, NodeJS, Knockout, Backbone etc etc. And so decided to learn NodeJS first, and have set it up on a local vm of ubuntu server.
So was wondering if NodeJS was supposed to be paired with another server software like apache,nginx, etc. And let apache/nginx just serve up the basic pages and then just let node do the data communications since their site says its "for easily building fast, scalable network applications".
Because I have seen several questions on S.O. asking how to get NodeJS to run on port 80, which implies they want to run node as a regular server or they just dont want to have to always specify a port when doing requests. And have not seen anyone comment or say that node was not meant to be used like a regular server. So was hoping to get to an answer on this.
Node.js can be used standalone, out there are good frameworks to do it like express. You can clusterize your process in the same physical machine (and the same port) really easy via its native module cluster. Also, I'm sure you can use Node.js like a reverse proxy too, but some developers prefer using other tools to do it (in my enterprise, we use Nginx with some of our node.js apps).
So, in short: You dont need Nginx or Apache at all, but you can use if you want. It's very cosy to some people use Nginx to do the load balance, or even other stuff like handle the https or server static content. It's your choice at the end.
You should play something with the native library http or https first, and then check express or another framework. You will see wich parts of Node.js you love and which do you dont feel awesome.