laravel 5.6 - connection refused - php

I test an laravel 5.6 app running on localhost:8000.
I have a separated vue project (not the one in laravel but external stand alone vue project) running on localhost:8080.
I want external vue to call a route from web.php in laravel:
Route::get('/stores/{store}', 'StoresController#show');
My code in external vue:
axios.get('http://localhost:8000/stores/68')///<-- I do have a record of 68 in database.
.then((response) => {
console.log(self.postdata);
}).catch((err) => {
console.log(err);
});
And I get error:
GET http://localhost:8000/stores/68 net::ERR_CONNECTION_REFUSED
I tried with IP address too:
axios.get('http://192.168.0.142:8000/stores/68')
And still get error:
GET http://192.168.0.142:8000/stores/68 net::ERR_CONNECTION_REFUSED
After much reading, I suspect is because of the csrf-token don't exist in external vue.
How can I resolve this?
Edit:
Below are the screencap of the error from the console:

Related

Proxy with express and laravel

I'm trying to create a proxy with my nodejs app (express) to my laravel app. I'm using the express-http-proxy module so I tried using this function:
app.use("/w", proxy("localhost:8081", {
https: false,
}));
but when I try to access the page http://localhost:8080/w an error appears
Error: connect ECONNREFUSED ::1:8081
at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1195:16)
Does anyone know how to solve it because I can't find anyone who has solved the request rejection with laravel

Laravel Socialite Login, localhost:8000 my laravel project is not running here... Guide please

I am trying to create Socialite Login using laravel. I have wamp server, and my project is running on http://localhost/SocialiteLogin/ <- on this url I am getting laravel logo/demo page.
Project is running well on my browser but when I type this address into (Create OAuth client ID->Authorized JavaScript origins) it gives me this error:
Invalid Origin: URIs must not contain a path or end with "/".
I have seen different videos related to this, their laraval project are running directly on localhost:8000 and they paste the same address into "Authorized JavaScript origins" but when I type this url(localhost:8000) I am getting error:
This site cannot be reached.
Please tell me how can I set my project so that it run on localhost:8000 so that I can use it in Create OAuth client ID.

I get a Failed to load resource: net::ERR_CONNECTION_REFUSED when running ionic app

I am using WAMP to to establish my pc as a server. I have some values in a database and now I want my ionic app to retrieve the data. In my app.js, I am using a get request to fetch whatever my php file gets from the db:
.controller('customersCtrl', function($scope, $http) {
$http.get("http://localhost//TempSensorTest/query.php")
.success(function (response) {$scope.names = response.records;});
When I open this url in the browser, I get a json object with the values.
However, when i run the app on my android phone the console prints:
Failed to load resource: net::ERR_CONNECTION_REFUSED http://localhost//TempSensorTest/query.php
Note that around 3 months ago I used the same method for a different app and it did work. However I do not know what might be casung this now?
In second line you have "http:http://localhost//TempSensorTest/query.php"
try to remove first "http:".

Running AngularJs and Laravel apps together under the same domain

So im trying to build 2 separate applications 1 that used as a backend (Laravel as a REST api) and Angular application as the client, eventually those 2 apps have to work together under the same domain as a single web app.
What im trying to accomplish:
My Angular app is a single page application that boot from index.html, all the routes are handled by Angular except /api/* that should be handled by Laravel app.
Im using 2 different apps in order to build web app more dynamic so i can easily change my backend framework and technologies and testing each app as a 'stand-alone' more easily.
I dont want to use CORS in my response headers because my REST API serves ONLY my Angular app and not other applications such as api for developers.
I want to use proxy that will foward all requests come from http://localhost:9100/api/* to: http://localhost:9000/api/*
Firstly im running Laravel on port 9000 by running:
php artisan serve --port 9000
And Angular app under port 9100 by running a gulp task (index.html is in the path ./src):
gulp.task('webserver', function(){
connect.server({
root: './src',
port: 9100,
middleware: function(connect, o) {
var url = require('url');
var proxy = require('proxy-middleware');
var options = url.parse('http://localhost:9000/api');
options.route = '/api';
return [proxy(options)];
}
});
});
Both apps work perfectly as a stand-alone, but when im trying to navigate to:
http://localhost:9100/api/v1/comments i receive the following error:
Error: connect ECONNREFUSED at errnoException (net.js:904:11) at Object.afterConnect [as oncomplete] (net.js:895:19)
I tried to investigate the cause of this problem, some people say it connected to my hosts file so i had to add the line:
127.0.0.1 localhost
But it doesnt work.
I tried different gulp task:
gulp.task('webserver', function() {
gulp.src("./src")
.pipe(webserver({
port: 9100,
livereload: true,
open: 'http://localhost:9100',
proxies: [
{
source: '/api', target: 'http://localhost:9000/api'
}
]
}));
});
And i receive the exact same error...
My develop environment is Windows 10 x64 bit.
Did you try to use http-proxy-middleware instead of proxy-middleware?
I experienced the same error with proxy-middleware. (Gulp browser-sync - redirect API request via proxy)
Error: connect ECONNREFUSED
at errnoException (net.js:904:11)
at Object.afterConnect [as oncomplete] (net.js:895:19)
Ended up creating http-proxy-middleware, which solved the issue in my case.
proxy-middleware somehow didn't work on the corporate network. http-proxy just did. (http-proxy-middleware uses http-proxy to do actual proxying)
Guess you are using gulp-webserver; The proxy can be added like:
var proxyMiddleware = require('http-proxy-middleware');
gulp.task('webserver', function() {
gulp.src("./src")
.pipe(webserver({
port: 9100,
livereload: true,
open: 'http://localhost:9100',
middleware: [proxyMiddleware('/api', {target: 'http://localhost:9000'})]
}));
});
Never found out why this error is thrown with proxy-middleware in the corporate network ...
Update:
Think this question has been answered:
It was a problem with the artisan server, had to run it this way:
php artisan serve --host 0.0.0.0
Source:
https://github.com/chimurai/http-proxy-middleware/issues/38
https://github.com/chimurai/http-proxy-middleware/issues/21#issuecomment-138132809

Configuring PhpStorm RESTful Client to work with Laravel

I'm trying to build RESTful API with Laravel using PhpStorm and artisan server, but when I try to test with Rest Client I receive this error:
For now I write only the GET method and I receive correct output in my browser with the address http://localhost:8000/users
This is my code:
routes.php
Route::resource('users','UserController');
UserController.php
public function index()
{
return \Response::json(User::all());
}
I tried also to add json in request window
php artisan serve --host 127.0.0.1 should do the trick.
Looks like PHPStorm does a lookup on localhost which results in 127.0.0.1. But php artisan serve binds to your local IPv6 address ::1.

Categories