Proxy error: ECONNREFUSED (Laravel)
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"
It sounds like issue #21.
(don't see anything weird in your configuration.)
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...
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.
Not sure what the difference is either, but the following also worked for me:
php artisan serve --host 127.0.0.1
Thanks that's help !
php artisan serve --host 127.0.0.1 thanks @awdyer