Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proxy error: ECONNREFUSED (Laravel) #38

Closed
lihaibh opened this issue Nov 13, 2015 · 6 comments
Closed

Proxy error: ECONNREFUSED (Laravel) #38

lihaibh opened this issue Nov 13, 2015 · 6 comments
Labels

Comments

@lihaibh
Copy link

lihaibh commented Nov 13, 2015

Im trying to foward all requests from my Express app that runs on port 4365 to another application that runs on port 9000.
In my case im trying to build a Laravel app that will be used only for api porpuses and angular app that will use that api.

This is the code i use:

var app             = require('express')()
    , proxyMiddleware = require('http-proxy-middleware')
    , http          = require('http').Server(app);
var context = '/api'; 
var options = {
    target: 'http://localhost:9000', // target host
    changeOrigin: true,               // needed for virtual hosted sites
    ws: true,                         // proxy websockets
};
app.use(proxyMiddleware(context, options));
http.listen(4365, "localhost", function(){
    console.log('Express server is listening on Port 4365 ');
});

Assume i have Laravel app running on port 9000 with api routing valid.
When i run it and open the browser and type in the url: http:\localhost:4365\api\v1\comments i assume to get the json, but it shows me an error: "Error occured while trying to proxy to: localhost:4365/api/v1/comments"

console output:
[HPM] Proxy created: /api -> http://localhost:9000
Express server is listening on Port 4365
[HPM] Proxy error: ECONNREFUSED. localhost -> "localhost:9000/api/v1/comments"

@chimurai
Copy link
Owner

It sounds like issue #21.

(don't see anything weird in your configuration.)

@lihaibh
Copy link
Author

lihaibh commented Nov 13, 2015

Wow thank you so much that actually worked!
Though why do we set host 0.0.0.0 and not 127.0.0.1?
Also this way how do i debug my api? i always start it up though PhpStorm...

@chimurai
Copy link
Owner

Np. Just remembered someone else bump into a similar issue.
No idea what the difference is between to two configurations....
I'm totally unfamiliar with Laravel.

But please do update this thread if you found the answer.

@chimurai chimurai changed the title Proxy error: ECONNREFUSED Proxy error: ECONNREFUSED (Laravel) Nov 13, 2015
@awdyer
Copy link

awdyer commented Apr 14, 2016

Not sure what the difference is either, but the following also worked for me:

php artisan serve --host 127.0.0.1

@mehdilamaaffar
Copy link

Thanks that's help !

@stanNo1
Copy link

stanNo1 commented Nov 10, 2016

php artisan serve --host 127.0.0.1
thanks @awdyer

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants