plouc / mozaik

Mozaïk is a tool based on nodejs / react / redux / nivo / d3 to easily craft beautiful dashboards
http://mozaik.rocks
MIT License
3.61k stars 363 forks source link

Could not proxy request /config from localhost:3000 to http://localhost:5000 #118

Closed sourcesoldier closed 7 years ago

sourcesoldier commented 7 years ago

I'm trying to run the mozaik2 demo locally on my Mac with npm installed thru homebrew.

It launches the browser window but then throws an error. Please see screenshot attached.

image

Current env versions:

npm -> 4.1.2 node -> 7.6.0

elementsweb commented 7 years ago

I've experienced the same issue, I fixed it by adding this at the top of my config.yml file:

host: 0.0.0.0
port: 3000
andrewmurray commented 7 years ago

Hi, I'm experiencing the same problem as @sourcesoldier. @elementsweb, could you provide a bit more context to those settings that you added? I've made the same change and it's not helping. Does the top 15 lines of your config look like this?

#
# mozaik generic demo dashboard
#
# It's not required, but you should add this env var,
# without it, you'll probably reach the API rate limit.
#
# GITHUB_API_TOKEN=xxxxx
#
host: 0.0.0.0
port: 3000

# define duration between each dashboard rotation (ms)
rotationDuration: 10000
# define the interval used by Mozaïk Bus to call registered APIs
apisPollInterval: 100000
frankwallis commented 7 years ago

I think the solution to this is to run node server.js instead of npm start

elementsweb commented 7 years ago

@andrewmurray your config looks good. I think the reason I set the port to be 3000 explicitly was because it was trying to proxy port 3000 to port 5000 - I couldn't see any reason for it doing this so set it to 3000 in the config.

As for for the host being set to 0.0.0.0 - this is useful if you want to preview your dashboard on another device connected to your private network.

@frankwallis I think you might be right, this rings a bell.

plouc commented 7 years ago

If you want to be able to proxy from the dev server to Mozaïk server, you can configure it through package.json.

marcmoo commented 6 years ago

i mean, you have not start your backend server!!!!! try start both backend and front end server concurrently

mahesh-cn commented 6 years ago

Had a similar problem and realized that I was inside the client folder rather than the parent server folder when I ran "npm start"

dzarasov commented 6 years ago

Spent all day fixing this, so this solution works for me:

"proxy": { "/api/*": { "target": "http://[::1]:8080" } }

georgemarin commented 6 years ago

If anyone else had this problem, how I solved it all the time, replace localhost to 127.0.0.1 in your package.json proxy

dzarasov commented 6 years ago

To avoid all this problems use nginx, super easy and will handle all this cases.

gaborszekely commented 6 years ago

Guys, I too was getting this error message all afternoon and it was driving me crazy!

What fixed it for me was, I was running concurrently and had originally set up my scripts like this: "start": "nodemon server.js", "client": "npm start --prefix client", "dev": "concurrently \"node start\" \"npm run client\""

However, once I changed it to this, the problem went away. "server": "nodemon server.js", "client": "npm start --prefix client", "dev": "concurrently \"npm run server\" \"npm run client\""

Hope this helps!

chethanbhat commented 5 years ago

My script started working when i eliminated && Previously it was "dev": "concurrently \"npm run client\" && \"npm run server\"" Changed it to "dev": "concurrently \"npm run client\" \"npm run server\""

ANVESH96 commented 5 years ago

I got the same issue and resolved it by changing proxy to "http://localhost:5000" instead of "https://localhost:500"

edgewood1 commented 5 years ago

This happened to me due to an error in the server's package.json. I had copied the package.json from an older app whose "main" property referred to a different server filename than the one I was using in the new app, and so had to correct this.

kapileswaran commented 5 years ago

Guys, I too was getting this error message all afternoon and it was driving me crazy!

What fixed it for me was, I was running concurrently and had originally set up my scripts like this: "start": "nodemon server.js", "client": "npm start --prefix client", "dev": "concurrently "node start" "npm run client""

However, once I changed it to this, the problem went away. "server": "nodemon server.js", "client": "npm start --prefix client", "dev": "concurrently "npm run server" "npm run client""

Hope this helps!

@gaborszekely U Mean Linux Commands?

Azizul08 commented 5 years ago

I got the same issue and resolved it by start my backend server

WafaBergaoui commented 5 years ago

I got the same issue and i resolved it by starting both backend and frontend server concurrently

jsmartio commented 4 years ago

first see if machine is listening on ports 3000 & 5000 sudo lsof -iTCP -sTCP:LISTEN -n -P
In my case it was not so I had to change my run command

mayowDev commented 4 years ago

Problem : after i say "npm start"

in vscode terminal : Proxy error: Could not proxy request /techs from localhost:3000 to http://localhost:8000/

in chrome: Cannot read property 'statusText' of undefined

} catch (err) { 21 | dispatch({ 22 | type: TECHS_ERROR,

23 | payload: err.response.statusText 24 | }); 25 | }

Solution : i used "npm run dev"

Because i was using concurrently "dev": "concurrently \"npm start\" \"npm run json-server\"",

the "techs" was in data.js file which was json data , so when you use npm start, it only starts the react-script-start "start": "react-scripts start", and it ignores data.js as our json server

That worked for me

ahmad-ali14 commented 4 years ago

for me, this happened because I was passing undefined value inside objectId() function. when I checked again and fixed that value >> problem solved

CABRALBRUNO000 commented 4 years ago

fala galera, para este erro, nenhuma das opções resolveram meu problema =(

bhasinkaran commented 4 years ago

I think the solution to this is to run node server.js instead of npm start

What would be server.js here? Like where would it be? what file is it and what does it do? thank you!

TesheMaximillan commented 4 years ago

Hey, Please Makesure the backend server is running.

nikhil026 commented 4 years ago

Although it is not specific to this project, I got the exact error in my react project when I was trying to proxy request from http://localhost:3000 to http://localhost:8080.

I solved this issue by removing "proxy": "localhost:8080" from package.json and creating a setupProxy.js file in the src folder with the following code:

const { createProxyMiddleware } = require('http-proxy-middleware');
module.exports = function(app) {
  app.use(
    '/api',
    createProxyMiddleware({
      target: 'http://localhost:8080',
      changeOrigin: true,
    })
  );
};

Reference: https://create-react-app.dev/docs/proxying-api-requests-in-development/#configuring-the-proxy-manually

crazyoptimist commented 4 years ago

If anyone else had this problem, how I solved it all the time, replace localhost to 127.0.0.1 in your package.json proxy

Thanks a lot!

Ashish1101 commented 4 years ago

use this settings in your package.json file in react

"proxy":"http://localhost:YOUR_BACKEND_PORT" "secure":false

if the above settings not work then replace localhost with 127.0.0.1

work for me

source

https://medium.com/@bryantjiminson/solving-proxy-error-could-not-proxy-request-xxx-from-yyy-from-local-reactjs-app-to-nodejs-app-f28f3548afb9

Rituraj26 commented 4 years ago

I started both server and client in separate terminal First i started server using nodemon server.js Next in another tab npm start --prefix client

csrapr commented 4 years ago

Everyone, make sure you also have the port number defined in your CLIENT package.json "server" property.

So go from "proxy": "http://localhost" to "proxy": "http://localhost:5000" Also try adding the "secure": false parameter, seems to help some people.

(oh, and restarting your computer could help as well. It's not the first time that for some reason when I close vscode the port stays in use)

nrc555 commented 4 years ago

package.json/backend { "name": "backend", "version": "1.0.0", "description": "", "main": "sever.js", "type": "module",

BingchenLi commented 4 years ago

I tried all of the solutions here and actually no one is not gonna actually solve this problem. In fact this problem is pretty random. But there is a pattern there, the 'Proxy error' always happens before the 'Server' starts. That's because the 'client' sends some request before the 'server' starts. Even if you use "dev": "concurrently "npm run server" "npm run client"" that does not guarantee the server will start before the client. The process really depends on the OS how to handle them. Unless you use a way to strictly specify the client must start after the server. That's why this error is pretty random. Actually, I think the answer of @TesheMaximillan should be the right one, some elaborations would be better.

Hey, Please Makesure the backend server is running.

Yafei18 commented 4 years ago

i mean, you have not start your backend server!!!!! try start both backend and front end server concurrently

Save my day!!!

Mnabawy commented 4 years ago

actually i found this issue related to the backend server is not running

itielMaimon commented 4 years ago

For anyone who uses Docker, running both back and front ends together with Docker Compose, change your proxy value in package.json to the name of your back-end container. e.g. "proxy": "http://server:8080". Your docker-compose.yaml file should look similar to this:

version: "3.8"
services:
  client:
    container_name: client
    build:
      context: ./client
    ports:
      - "3000:3000"
  server:
    container_name: server
    build:
      context: ./server
    ports:
      - "8080:8080"
rameez209 commented 4 years ago

I think the solution to this is to run node server.js instead of npm start

I was stuck on this problem for the last 3 days and you solved it. Thank you sooo much 👍

bkerz commented 4 years ago

How can i check if the backend is working well? I don't have any control of the backend. I tried almost all the solutions but none of them worked for me. I spent all the day just in this error. How frustrating it is.

Gaurang-1402 commented 3 years ago

Had the same problem. Realized that I used "https" instead of "http" in package.json while manually typing the proxy

arkhannanov commented 3 years ago

Also one variant what helped me. I changed my port on server. Was "proxy": "http://localhost:7070", changed to "proxy": "http://localhost:7080"

`const express = require('express') const app = express()

app.disable('etag') app.use(require('./routes'))

app.listen(7080, () => { console.log('BALK stubs are on port 7080!') console.log('---') }) `

Sanchitraina1999 commented 3 years ago

My problem was missing parentheses:

const router = require('express').Router;

Changing this to

const router = require('express').Router(); 
BilderLoong commented 3 years ago

Guys, I too was getting this error message all afternoon and it was driving me crazy!

What fixed it for me was, I was running concurrently and had originally set up my scripts like this: "start": "nodemon server.js", "client": "npm start --prefix client", "dev": "concurrently "node start" "npm run client""

However, once I changed it to this, the problem went away. "server": "nodemon server.js", "client": "npm start --prefix client", "dev": "concurrently "npm run server" "npm run client""

Hope this helps!

This solution inspires me, I change my script from

    "server": "nodemon server",
    "client": "npm start --prefix client",
    "dev": "concurrently -k \"npm:server\" \"npm:client\"",

to

    "server": "nodemon server",
    "client": "npm start --prefix client",
    "dev": "concurrently -k \"npm run server\" \"npm run client\"",

Then the error message is gone. Maybe something wrong with concurrently.

mehaksaini2811 commented 3 years ago

I was using the below configuration "server": "nodemon server", "client": "npm start --prefix client", "dev": "concurrently -k \"npm run server\" \"npm run client\"",

and did a restart. Worked for me!

udaypavan11 commented 3 years ago

Check if the issue is with the Monogo connection. I realized that my Password to connect to MongoDB got expired and updated that. Which is working fine for me now.

San411 commented 3 years ago

I've experienced the same issue, I fixed it by adding this at the top of my config.yml file:

host: 0.0.0.0
port: 3000

Thank you worked for me

AvneetSingh27 commented 3 years ago

If anyone else had this problem, how I solved it all the time, replace localhost to 127.0.0.1 in your package.json proxy

Thanks for your help. It worked for me

ayushkumar0507 commented 3 years ago

run the backend and frontend simultaneously

"server": "nodemon backend/server", "client": "npm start --prefix frontend", "dev": "concurrently \"npm run server\" \"npm run client\""

KG1414 commented 3 years ago

i mean, you have not start your backend server!!!!! try start both backend and front end server concurrently

Thank you!!!!!! Life saver! Why do i never see this simple tip anywhere?

Brilliant-Atosam commented 3 years ago

use this settings in your package.json file in react

"proxy":"http://localhost:YOUR_BACKEND_PORT" "secure":false

if the above settings not work then replace localhost with 127.0.0.1

work for me

source

https://medium.com/@bryantjiminson/solving-proxy-error-could-not-proxy-request-xxx-from-yyy-from-local-reactjs-app-to-nodejs-app-f28f3548afb9

This worked for me

shaharjacob commented 3 years ago

For anyone who uses Docker, running both back and front ends together with Docker Compose, change your proxy value in package.json to the name of your back-end container. e.g. "proxy": "http://server:8080". Your docker-compose.yaml file should look similar to this:

version: "3.8"
services:
  client:
    container_name: client
    build:
      context: ./client
    ports:
      - "3000:3000"
  server:
    container_name: server
    build:
      context: ./server
    ports:
      - "8080:8080"

Works for me! Thanks!

Saqib-diar commented 3 years ago

Proxy error: Could not proxy request /signup from localhost:3000 to http://localhost:8282/. See https://nodejs.org/api/errors.html#errors_common_system_errors for more information (ECONNREFUSED).

I got the same issue and I just solved it by only restart both of the server, you need to run both of the server running.

Thanks me ltr:)

ninyhorlah commented 2 years ago

For anyone who uses Docker, running both back and front ends together with Docker Compose, change your proxy value in package.json to the name of your back-end container. e.g. "proxy": "http://server:8080". Your docker-compose.yaml file should look similar to this:

version: "3.8"
services:
  client:
    container_name: client
    build:
      context: ./client
    ports:
      - "3000:3000"
  server:
    container_name: server
    build:
      context: ./server
    ports:
      - "8080:8080"

thank you.... this solved mine

sarangkkl commented 2 years ago

I've experienced the same issue, I fixed it by adding this at the top of my config.yml file:

host: 0.0.0.0
port: 3000

Any idea how to fix it on react app