I have deployed a web application in Heroku using node.js but within the application I need to make a request to an HTTP endpoint that returns a JSON file. While making the request, I get the a Mixed content error. I understand this happens because my application has been served through HTTPS but the request is HTTP. How could I tell heroku to serve my application as HTTP or what should I do to make it HTTP? Will this solve the problem?
Related
Online examples will usually include the socket.io library using
<script src="/socket.io/socket.io.js"></script>
However, I was wondering why this works even though I don't have a socket.io folder in my directory. Does running node index.js automatically create this socket.io folder?
The socket.io server listens for all incoming requests that start with /socket.io and "steals" those requests for itself, keeping them from the regular http server that the socket.io server is sharing.
When the socket.io server sees that this is a request for the socket.io.js file, the socket.io server then reaches into its own node_modules/socket.io/client-dist directory to get the client-side socket.io.js file and sends it back to the client.
If you look at what you will find in node_modules/socket.io/client-dist directory, you will see the file socket.io.js sitting there. That's the file that the socket.io server sends back to the client. This is client-side code, only on the server for the purposes of being sent to the client when it asks for it.
Keep in mind that responses to incoming paths with a nodejs http server are not necessarily about file directories on the server at all. If any code hooked up to the http server handles an incoming request, it can decide what it wants to send as the response, from anywhere in the server (whether from a file or not). Only specific middleware tools like express.static() look on the server's hard disk for a directory that matches the incoming request.
I have a project with a client folder containing a React app bootstrapped with create-react-app. I also have a server folder with an express API server running on localhost:80.
Originally, I ran my frontend and backend as separate servers, making requests to the API server by making requests with fetch("url") and using "proxy": "localhost:80" in my package.json
I have recently altered the project so that my server serves the static frontend files like so: app.use(express.static(path.resolve(__dirname, "../client/build")))
I then tested running the server on two different ports 80 and 3000, and the frontend and backend both worked perfectly but I believed it would only work when the server was run on port 80
How does my frontend now know where to call the API server when it is running on different ports?
Proxy is used in the development environment and after that when you make build then its convert into the static HTML, CSS and JS files and that can be run in any port using node if you try that in a different port than it will also work as same
Proxy is not made for the production environment
https://github.com/facebook/create-react-app/issues/1087
I have purchased a subscription to NameCheap VPS service.
I have nodejs api running locally that I want to expose.
Currently when visiting mydomain.com a static page is served. How do I expose my nodejs api and handle requests to for example mydomain.com/books?
I have run the steps descrived here
The following guide is useless.
I have a nginx server where I have an api deployed at localhost:5000
On the same server I have a Vuejs app which is deployed at localhost:3000 and then through nginx reverse proxy served from www.mysite.com.
the frontend uses axios to make calls to the api. But everytime it happens, I get a connection refused error to localhost:5000.
Why is this happening and how can I resolve it.
Note: If I serve localhost:5000 api also via a domain like api.mysite.com using nginx reverse proxy and call api from this domain then it works fine. But I don't want to do that and instead want to use localhost:5000 to call the api.
Please check the port is listed by using the following command if you use Linux
sudo netstat -tnlp | grep :5000
If there is process running, then fine. Try changing the localhost to 127.0.0.1:5000
Let's suppose a backend application, which exposes some Rest API, running on a Jetty webserver at address 192.168.1.10:8889.
I would like to have a frontend application (html/javascript only, on a apache2 webserver) running at the same IP but on a different port (e.g. 8000), which should consume the API exposed by the backend application.
How can i get this architecture working without get into "No 'Access-Control-Allow-Origin'" error?
I think that you should install a nginx proxy.
configure it as a reverse proxy you can see documentation here :
https://www.nginx.com/resources/admin-guide/reverse-proxy/
You can search on google for more specific documentation on what you want to do.