Proxy with express and laravel - php

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

Related

Symfony 5.3, Mercure and Vue -> SSL connect error for "https://localhost:8000/.well-known/mercure"

I'm trying to make a publish with the Hub Interface but everytime I get this error
SSL connect error for "https://localhost:8000/.well-known/mercure"
I'm running mercure with the Symfony Local Web Server, so mercure it's running on https://localhost:8000/.well-known/mercure. I have checked and it is running but I can't manage to make a publish. I'm making this call from a controller which is called from Vue.
$update = new Update(
[
sprintf("/conversaciones/%s", $conversacion->getId()),
sprintf("/conversaciones/%s", $recipiente->getUsuario()->getNombre()),
],
$mensajeSerializado,
true
);
$this->hubInterfacePublisher->publish($update);
Some comment on other question from Stackoverflow mentioned this:
Mercure with symfony not working with vue
Mecure dont support self signed certificates and you have to add verify_peer: false in config/dev/framework.yaml under http_client.default_configuration
Tryed it, but didn't work for me. Also, for what I have read, it is not recommended to set it false HTTP Certificates
I also tryed to change https to http on my .env, but I got a 401 Unauthorized.
I have checked on symfonycast tutorials and they have the .env enviroments on localhost:8000 so I think that can't be it, but I don't know what else I can try.
For what I know it has to do with CORS. But don't know how to fix it.
Any help is appreciated,
Thank you :)

Laravel7 CORS : blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin'

Use case: VueJS/Laravel app has inventory. Calling Magento2 using SOAP API to update Qty from VueJS/Laravel.
Error as shared below:
Access to XMLHttpRequest at
'http://xx.yyy.abc.123/rest/V1/integration/admin/token?username=admin&password=xxxxx'
from origin 'http://192.168.0.x' has been blocked by CORS policy:
Response to preflight request doesn't pass access control check: No
'Access-Control-Allow-Origin' header is present on the requested
resource.
Note: I am a beginner in this domain. I might be asking stupid questions. Please bear with me and requesting help here.
Tools/Apps used:
Laravel Framework 7.9.2 /Running on http://192.168.0.x
VueJS /Running on http://192.168.0.x
Magento2 /Running on http://xx.yyy.abc.123
Postman (Tool used to test SOAP API)
Debugging efforts:
URL http://xx.yyy.abc.123/rest/V1/integration/admin/token?username=admin&password=xxxxx
Tried from postman: It works, Apended token into postmane and got the response.
Making AXIOS call from VueJS/Laravel application to Magento2:(Failed)
Origin: http://192.168.0.x
Magento2: http://xx.yyy.abc.123
axios.post("http://xx.yyy.abc.123/rest/V1/integration/admin/token?username=admin&password=xxxxx",
{
})
.then((response) =>
{
console.log("response.data",response.data);
this.apiResponse = response.data;
//this.getproduct();
})
.catch(error =>
{
alert('ERROR GETCATEGORY!!!! No Data found');
console.log(error.response);
});
Checked for 2 days now about CORS error and found that this is enabled by default in Laravel 7. Not sure why I am seeing this error even after using Laravel 7. There are very few answers or solutions specific to VueJS with Laravel 7.
Question:
What does this error means. I thought it is just calling from webpage1 to webpage2, it does not seem to work.
Do I need to make any changes on my VueJS/Laravel application. Am I missing anything further.
Please do let me know if you need any more information to help me in this regards.
Thanks for your help.
Regards,
I had got the same CORS error while working on a Vue.js project. I finally solved this issue just today in the morning. You can resolve this either by building a proxy server or another way would be to disable the security settings of your browser (eg, CHROME) for accessing cross origin apis. Both these solutions had worked for me. The later solution is the easiest solutoion and does not require any mock server or a proxy server to be build. Both these solutions can be resolved at the front end.
You can disable your browser (CHROME) security settings for accessing apis out of the origin by typing the below command on the terminal:
/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --user-data-dir="/tmp/chrome_dev_session" --disable-web-security
After running the above command on your terminal, a new chrome window with security settings disabled will open up. Now, run your program (npm run serve / npm run dev) again and this time you will not get any CORS error and would be able to GET request using axios.
Hope this helps!

laravel 5.6 - connection refused

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:

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

how to configure facebook api in localhost in xampp or wamp server? what is php.ini settings requirement to use it?

I m new to use of facebook api after some googling i found facebook api from this link:
https://github.com/facebook/facebook-php-sdk
after download this package i try to execute example code from this package but it returns an error like:
Fatal error: Uncaught CurlException: 6: Could not resolve host: graph.facebook.com; Host not found thrown in D:\xampp\htdocs\testing\phpdemo\fb\src\base_facebook.php on line 994
to solve this problem i try too much googling but i doesnt get positive result from there.
If anybody know what kind of possibilities for this problem then please help.
here is may be two posibilities like:
1) Do you have any firewalls? The problem is not about configuration is just CURL can't do requests to graph.facebook.com and possible any website. Try disable any firewalls that may be blocking your CURL requests
2) From my experience you can't use facebook APi local, however they have a free host provider,Heroku, try it. Also don't forget to replace YOUR_APP_ID and YOUR_APP_SECRET with your app Data.
You can get help here,https://stackoverflow.com/questions/16294630
From my experience you can't use facebook APi local, however they have a free host provider,Heroku, try it.
Also don't forget to replace YOUR_APP_ID and YOUR_APP_SECRET with your app Data.

Categories