I'm trying to get a local api and local website(consumer of api) to work together for last two days but no joy.
Local Api: apishop.test
Local Consumer: frontendflex.test
When i connect to a live api (like fakestoreapi.com) it works fine from Local Consumer website. Both my own local api and the fakestoreapi produce valid json on screen
I have tried various ways to communicate with the local api that dont work.
$res=json_decode(file_get_contents('http://apishop.test/products/' . $request->product)
error..
file_get_contents(https://apishop.test/products/2): Failed to open stream: HTTP request failed! HTTP/1.1 500 Internal Server Error
$res = Http::acceptJson()->get('http://apishop.test/products/' . $request->product);
ErrorException
Undefined property: Illuminate\Http\Client\Response::$title (View: C:\xampp\htdocs\frontendflex\resources\views\shop\product.blade.php). This makes sense beacause if I dd($res) it is 500 internal server error like file_get_contents()
So to curl...
curl_setopt($handle, CURLOPT_URL, 'http://apishop.test/products/2');
curl_setopt($handle, CURLOPT_RETURNTRANSFER, true);
curl_setopt($handle, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']??null);
curl_setopt($handle, CURLOPT_HTTPHEADER, array('Content-Type:application/json'));
//$res= json_decode(curl_exec($handle), true); //Attempt to read property "title" on null
//$res= curl_exec($handle); //Attempt to read property "title" on string
curl_close($handle);
But when I dd($res) it spews out crazy error data at which the top is....
Illuminate\Database\QueryException
SQLSTATE[42S02]: Base table or view not found: 1146 Table 'frontendflex.products' doesn't exist (SQL: select * from products where products.id = 2 limit 1)
http://apishop.test/products/2
There is NO products table here, it is in api website. I'm running frontendflex.test here. So getting more curious, I deliberately caused an error in api website code and it picked it up on the consumer website frontendflex.test. What's going on here ?? Both websites are totally separated but under xampp. Head-banging for two days now. Any help appreciated
Well in desperation i created a brand new clean laravel project, just one controller and one route to access the api and it worked. So, I need to drill down as to what is happening with the other site. Mis-config somewhere.
Edit:
I discovered that for some reason if i access the consumer website (frontendflex.test) by php artisan:serve (http://127.0.0.1:8000/doda)it accesses the api site apishop.test no problem. Weird, but not wonderful!! Anybody out there that can shine a light on this?
Edit: Discovered a workaround.
Change port for consumer site to http://frontendflex.test:8080/doda
NameVirtualHost *:8080
<VirtualHost 127.0.0.1:8080>
DocumentRoot "C:/xampp/htdocs/frontendflex/public"
ServerName frontendflex.test
</VirtualHost>
Changed to this in apache vhosts file
This works but i would like to know why other way does not work.
Hope this helps someone somewhere someday :)
Related
Sorry for this long post I don't have any other way to describe it in short.
I have two Laravel application which are hosted in two subdomains of the same domain. One is
form.example.com another is dashboard.example.com.
The Dashboard app sends a http request to the Form app to get some JSON data. And the code it uses to send the request is like this:
$url = "https://form.example.com/api/v2/get/orders/" . urlencode($log->lastpull);
$client = new \GuzzleHttp\Client();
$request = $client->request('GET', $url);
$json = $request->getBody();
$objects = (json_decode($json));
Now the problem is that Dashboard app sometimes get a blank JSON or some error message in return from the Form app when this request is made.
However the same code works file in the localhost and when I look up the URL (https://form.example.com/api/v2/get/orders/) I get a valid JSON object. Which indicates that Form app is fine.
The error message I talked about I get from the Form app as a response for the HTTP request is this:
SQLSTATE[42S02]: Base table or view not found: 1146 Table 'dbl5qxvxfrl9tl.products' doesn't exist (SQL: select * from `products` order by `index` asc)
The problem with this error message is that the database it mentions 'dbl5qxvxfrl9tl' belongs to the Dashboard app! The app which is making the request.
I have no idea why the Form app is looking for its table on the Dashboard app's database. It only occurs when I host the Dashboard app on my shared hosting's server. In localhost it works fine.
I tried to export the stack trace from the error page but for some reason it was not letting me to export. So I have saved the html page:
drive.google.com/file/d/1elbJhv4BpDNlxC2Ji_463dDLndjzjbm6/view?usp=sharing
(I have replaced the domain name in this html file for privacy reasons)
As user #apokryfos commented on the main post, solution to this problem is this:
If these are two separate Laravel apps in different paths then you can also try running php artisan config:cache on both of them to generate a cache for the config so it doesn't read environment variables anymore (in case there's some cross-over)
the gmail smtp-relay works fine using the sync driver, but if we queue the email we this error. cleared config, cache, & restarted queue workers. tested in prod and dev, same results
[2021-01-24 20:04:22] production.ERROR: Expected response code 250 but got an empty response {"exception":"[object] (Swift_TransportException(code: 0): Expected response code 250 but got an empty response at /home/****/****/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Transport/AbstractSmtpTransport.php:448)
were wondering is this because of serialization and something is not making it through that process???
using latest stable release of laravel >8.0. gmail smtp is authenticating just fine, per why the sync driver sends emails easily. maybe there needs to be a timeout on the queue jobs so they dont barrage gmail so quickly? also our code works fine using sendgrid for example as the smtp relay. thanks.
See https://laracasts.com/discuss/channels/laravel/laravel-swift-mailer-exception-expected-response-code-250-but-got-an-empty-response-using-gmail-smtp-relay-database-queue-driver
Update your AppServiceProvider.php
add this inside boot();
// Fix for SwiftMailer Service;
$_SERVER["SERVER_NAME"] = "your.domain.name";
For users of smtp-relay.gmail.com, if you use localhost/127.0.0.1 as domain during developments, you probably need to change the domain name to use in EHLO command to begin the transaction. I solved this by adding &local_domain=dev.mydomain.tld at the and of my DSN.
smtp://smtp-relay.gmail.com:587?encryption=tls&local_domain=dev.mydomain.tld&...
For SwiftMailer Symfony bundle (since 2.4.0), you can set the local_domain config parameter:
// config/packages/dev/swiftmailer.yaml
swiftmailer:
...
local_domain: dev.mydomain.tld
Explanation for the 2 previous Answers
if $_SERVER["SERVER_NAME"] is the solution:
When you are using cron
The reason is that $_SERVER["SERVER_NAME"] is null when cron is executed. $_SERVER["SERVER_NAME"] is usually only defined for http access.
Example implementation (laravel):
if (!isset($_SERVER['SERVER_NAME'])) {
$url = config('env.APP_URL');
$domain = mb_ereg_replace("http(s)? ://", "", $url);
$domainParts = explode('/', $domain);
ini_set('server_name', count($domainParts) > 0 ? $domainParts[0] : $domain)
}
References :
Cron Job $_SERVER issue
https://github.com/swiftmailer/swiftmailer/issues/992
if 'local_domain' is the solution
When you have a mailhost setting of MAIL_HOST=smtp-relay.gmail.com in your laravel project
The reason is that if local_domain' is not set, the protocol for mail communication with Gmail will be EHLO [127.0.0.1]` and the communication will be disconnected.
By the way, I used gmail->gmail alias and did not need relay in the first place, so I solved the problem by setting MAIL_HOST=smtp.gmail.com.
References:
https://blog.trippyboy.com/2021/laravel/laravel-expected-response-code-250-but-got-an-empty-response/
I had to deal with both of them because of cron messaging and MAIL_HOST=smtp-relay.gmail.com in my environment.
I hope this information will help you.
I need to update a website from a colleague to just add a LDAP connexion.
I use EasyPHP devserver 17.0 with php 7.1.3 and MySQL 5.7.17.
I've read a lot of docs etc to be started and to recover the site in local as it is working actually.
Everything was working so I began to add a login form etc... but when I tried to test a link from the website, it return me the error "Sorry, the page you are looking for could not be found". So I began to search on forums I found some results about routes etc and everything I've tested didn't worked.
So, I decide to use the backup from the website as it was when I juste restore it in local(I precise link to other page and everything was working). I check the link and again, "Sorry, the page you are looking for could not be found". I decide to try another developement tool and download XAMP, exactly same error. I tried with Wamp, Laragon always same error.
In the apache conf mod_rewrite is enabled.
My laravel framework version is: 5.5.39
So my folder look like:
Laravel 5.5.39
The content of routes > web.php:
Route::get('/', function () {
return view('welcome');
})->name('welcome');
// Holidays
Route::get('/holidays/create', 'HolidayController#create')->name('holidays.create');
Route::post('/holidays', 'HolidayController#store')->name('holidays.store');
Route::get('/holidays/{holiday}/delete', 'HolidayController#destroy')->name('holidays.destroy');
Route::get('/holidays/{holiday}/edit', 'HolidayController#edit')->name('holidays.edit');
Route::post('/holidays/{holiday}', 'HolidayController#update')->name('holidays.update');
// Leave types
Route::get('/types/create', 'TypeController#create')->name('types.create');
Route::post('/types', 'TypeController#store')->name('types.store');
Route::get('/types/{type}/delete', 'TypeController#destroy')->name('types.destroy');
Route::get('/types/{type}/edit', 'TypeController#edit')->name('types.edit');
Route::post('/types/{type}', 'TypeController#update')->name('types.update');
// Users
Route::resource('users', 'UserController');
Route::get('/births', 'UserController#getAllBirths')->name('births');
// Leaves
Route::get('/calendar', 'LeaveController#index')->name('calendar');
Route::post('/leaves', 'LeaveController#store')->name('leaves.store');
Route::post('/leaves/{leave}', 'LeaveController#update')->name('leaves.update');
Route::get('/leaves/{leave}/delete', 'LeaveController#delete')->name('leaves.delete');
Route::get('/leaves', 'LeaveController#getAll')->name('leaves');
Route::get('/config', 'ConfigController#index')->name('config');
// Stats
Route::get('/statistics', 'StatsController#index')->name('stats.index');
Auth::routes();
I don't know what I could do but please ask me if you need more information to help me.
If it can help; gitLab link from the site I'm trying to restore: https://gitlab.com/balsigergil/btplan
To fix the problem I had to change the VirutalHost DocumentRoot so the root is the public directory.
DocumentRoot "C:/Users/sadm-m263733/Desktop/EasyPHP-Devserver-17/eds-www/siteBTPlan/public"
The laravel project runs at another system with a fixed ip.
If I access the project on another computer via this line:
http://61.211.45.158/appi/public/auth/login
(changed to original ip for privacy)
it works so far but if I login the url does change to this:
http://61.211.45.158/auth/login
and I get the error
Object not found ... 404
The laravel project works if I call it locally via localhost....
I do not know why this is happening really big thanks for any help.
EDIT:
I removed the authentification and somehow it show the page now just without the login and register, does anyone know why?
I commented this line:
Route::group(['middleware' => 'auth'], function ()
{
You have wrong web server configuration on the remote machine. Web server should be pointed to a public directory, for example /home/someuser/appi/public, but not to /home/someuser/. Edit Apache config file (do not edit .htaccess), you should have similar lines in it:
DocumentRoot "/path_to_appi/appi/public"
<Directory "/path_to_appi/appi/public">
Then restart Apache to make everything work.
I found a strange error after migration to new hosting.
We have moved our server from Moscow and London.
I added a new IP to Google Developers Console (178.79.158.44).
After that, a part of the IPA worked good:
1) "https://www.googleapis.com/oauth2/v1/userinfo" is working good
2) But "https://www.googleapis.com/calendar/v3/calendars/$calendar_id/events" - always return "403 Forbidden" error
What am I doing wrong?
On the old server in Moscow, everything is still working well.
My project ID "rapid-arbor-522"
I solved the problem.
The fact was that the new server has been configured and IPv4 and IPv6.
And apparently, some requests went through IPv6 that has not been configured in the console.
Once I disabled ipv6 (sysctl -w net.ipv6.conf.all.disable_ipv6 = 1) it worked =)