Not allowed to request resource (fetch error) - javascript

I'm trying to hosting my Express server on my personal computer because it needs Linux + Wine (for building commands). And for using him, I've opened my ports, and I can access to my Express page normally, but if I try to fetch the URL from the Express app, it won't work.
Here's the errors : https://imgur.com/4hdznw7
Here's the code of my Express app : https://hastebin.com/mihizegatu.typescript
Warning I've tried to publish my Express app on Heroku, and I can fetch it. But if I fetch my Express app from my personal computer, it won't works (errors upper).
Do you have an idea of why it doesn't work ?
Thanks in advance,
Corentin de Maupeou

Related

React-router and Express server on same port

I am developing a website that uses react and react-router for the frontend and express for the server. I'm trying to implement session based authentication by using express-session, however, the only way that I've been able to get the cookie to save in the browser was by having the express server run on the same port that react-router is (localhost:3000).
I'm not sure how to phrase this question, but is this "OK"? There doesn't appear to be any obvious problems caused by doing this but I'm not sure if having them both run on the same port is "good" or "bad".
Could there be any problems caused by having react-router and express running on the same port? If so, how can I get express to save the cookie on a port that's different from the express server itself?
I figured it out. YES this is bad, the solution is to set up a proxy for create react app
https://create-react-app.dev/docs/proxying-api-requests-in-development/

how to connect express app in VM from internet?

I am running an express app in node.js on Azure Linux VM, and I want to connect this website from my personal computer.
const express = require('express');
const app = express();
app.listen(3000, () =>
{
console.log("Server is running..");
})
And for ex. in my computer, I can just run localhost:3000 but on VM, I cant reach.
The public ip adress of VM is 40.XXX.XX.252 and I try to connect on my browser like this : http://40.XXX.XX.252:3000 but it doesn't work either..
I know it is really common question but i tried everything that is suggested and I couldnt fix.
ps: I tried to run this app on my computer and again, I could connect through localhost:3000 but not from another computer with my computer's public ip.
Problem causes:
It must be that port 3000 is not open. You can open port 3000 through commands to set it. (The settings in the firewall also need to be checked)
But I personally think this is not safe.
I recommend using an intranet penetration tool, which is the safest way to access through the generated link, because sometimes the public ip assigned by the operator is not fixed. Here I recommend using ngrok linux version.
You also can refer to my answer in another post.
sending http request from azure web app to my machine

How to handle backend API request for create-react-app bootstrapped app which is build and ran using "serve-s build" on AWS ec2?

I have create-react-app bootstrapped application which I build and then serve it to the static server using serve-s build. The React app is running on http://locahost:3000.
This app talks to my backend REST API(using java) which is running on http://locahost:8080.
Inside my React application, I have set axios.default.baseURL=http://localhost:8085/api.
Everything is fine on the localhost on my system. The React app talks to http://localhost:8085/api/xyz for CRUD operations and everything works great.
Now I have to deploy the project on AWS EC2 instance. The MySQL and REST API got deployed and rest API there is running on same instance on the port 8085 as http://locahost:8085. I have Apache server configured which sends the hostname(www.myxyzwebsite.com) to the http://locahost:3000 on the server. Everything is fine till now. The home page is visible on the browser.
Now, when the React app tries to communicate to the REST API from the browser, it is sending the request to the http://locahost:8085. Obviously, now the browser looks for some service running on port 8085 on my system and it couldn't find. Ideally, the request should go to the server with my hostname(www.myxyzwebsite.com/api/users/puspen). How to make this REST API call looks like an actual call like www.myxyzwebsite.com/users/pusp?
NOTE: Please note that this is not a server-side-rendered application.

How to connect frontend and backend on domain

I don't really have experience with backend and how things work together. I have created a simple live message sending app with node.js and socket.io. When I host a static web server on my machine (http-server which runs on local port using node.js) my app works perfectly fine but when I upload it on my host or github pages just for test, the backend doesn't seem to work. I uploaded all my files with an FTP program and the frontend loads fine but the backend doesn't. Do I have to know something like Django or ASP.NET to make these work on my host?
EDIT: One more thing, first line in my server.js is const io = require('socket.io')(3000)and in my script.js - const socket = io('http://localhost:3000')where 3000 and localhost:3000 stands for local host in my machine. What do i need to put instead of these?
You probably need to install and setup Node.js on your server, contact yout hosting provider for node installation if the option isn't available in yout cPanel.

ReactJS could not proxy request from localhost:3000 to localhost:3003

I am writing a SPA using create-react-app and am using an expressjs server as my backend. For development I run my frontend test server on port 3000 and my backend expressjs test server on 3003.
I make many API calls client side using Axios so for development convenience I have defined proxy: "http://localhost:3003" in my package.json
This works fine on my laptop, but when running on my workstation I constantly get the error when accessing my app:
Proxy error: Could not proxy request /sockjs-node/487/wrst1bub/websocket from localhost:3000 to http://localhost:3003/. See https://nodejs.org/api/errors.html#errors_common_system_errors for more information (ECONNRESET).
I have no idea where this is coming from and I do not use sockjs in any capacity as far as I know. This is a console error and it does not crash my app but it is very annoying and I would like to get rid of it. Any help is greatly appreciated.
In my case, I was using Firefox and for some reasons, it gives me the same error. I tried to use Chrome and it worked!

Categories