2019-07-12 07:03:30 +02:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Invoice Ninja (https://invoiceninja.com)
|
|
|
|
*
|
|
|
|
* @link https://github.com/invoiceninja/invoiceninja source repository
|
|
|
|
*
|
2020-01-07 01:13:47 +01:00
|
|
|
* @copyright Copyright (c) 2020. Invoice Ninja LLC (https://invoiceninja.com)
|
2019-07-12 07:03:30 +02:00
|
|
|
*
|
|
|
|
* @license https://opensource.org/licenses/AAL
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace App\Http\Middleware;
|
|
|
|
|
|
|
|
use App\Libraries\MultiDB;
|
|
|
|
use Closure;
|
|
|
|
|
|
|
|
class SetDomainNameDb
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Handle an incoming request.
|
|
|
|
*
|
|
|
|
* @param \Illuminate\Http\Request $request
|
|
|
|
* @param \Closure $next
|
|
|
|
* @return mixed
|
|
|
|
*/
|
|
|
|
|
|
|
|
public function handle($request, Closure $next)
|
|
|
|
{
|
2019-12-30 22:59:12 +01:00
|
|
|
$error = [
|
2019-09-24 00:37:38 +02:00
|
|
|
'message' => 'Invalid token',
|
|
|
|
'errors' => []
|
|
|
|
];
|
2019-12-30 22:59:12 +01:00
|
|
|
/*
|
2019-07-12 07:03:30 +02:00
|
|
|
* Use the host name to set the active DB
|
|
|
|
**/
|
2019-12-30 22:59:12 +01:00
|
|
|
if ($request->getSchemeAndHttpHost() && config('ninja.db.multi_db_enabled') && ! MultiDB::findAndSetDbByDomain($request->getSchemeAndHttpHost())) {
|
|
|
|
if (request()->json) {
|
2020-02-05 05:06:03 +01:00
|
|
|
return response()->json($error, 403);
|
2019-12-30 22:59:12 +01:00
|
|
|
} else {
|
2019-09-23 07:59:01 +02:00
|
|
|
abort(404);
|
2019-12-30 22:59:12 +01:00
|
|
|
}
|
2019-07-12 07:03:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return $next($request);
|
|
|
|
}
|
|
|
|
}
|