Skip to content

Commit

Permalink
表示速度を改善
Browse files Browse the repository at this point in the history
CSRFトークンのリクエストの際に不要な処理を実行させないようにした
  • Loading branch information
ryuring committed Jul 18, 2024
1 parent e2da9dc commit 895aec0
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 10 deletions.
16 changes: 12 additions & 4 deletions plugins/baser-core/src/BaserCorePlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,19 +150,27 @@ public function bootstrap(PluginApplicationInterface $app): void
Log::setConfig(Configure::consume('Log'));
}



/**
* プラグインロード
*/
if (!filter_var(env('USE_DEBUG_KIT', true), FILTER_VALIDATE_BOOLEAN)) {
// 明示的に指定がない場合、DebugKitは重すぎるのでデバッグモードでも利用しない
\Cake\Core\Plugin::getCollection()->remove('DebugKit');
}

// CSRFトークンの場合は高速化のためここで処理を終了
if(preg_match('/\?requestview=false$/', $_SERVER['REQUEST_URI'])) {
return;
}

if (BcUtil::isTest()) $app->addPlugin('CakephpFixtureFactories');
$app->addPlugin('Authentication');
$app->addPlugin('Migrations');

$this->addTheme($app);

if (!filter_var(env('USE_DEBUG_KIT', true), FILTER_VALIDATE_BOOLEAN)) {
// 明示的に指定がない場合、DebugKitは重すぎるのでデバッグモードでも利用しない
\Cake\Core\Plugin::getCollection()->remove('DebugKit');
}
$plugins = BcUtil::getEnablePlugins();
if ($plugins) {
foreach($plugins as $plugin) {
Expand Down
7 changes: 7 additions & 0 deletions plugins/baser-core/src/BcPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,13 @@ public function routes(RouteBuilder $routes): void
$routes = $this->frontPageRouting($routes, $plugin);
}

// CSRFトークンの場合は高速化のためここで処理を終了
$request = Router::getRequest();
if(!$request->is('requestview')) {
parent::routes($routes);
return;
}

// プレフィックスルーティング
$routes = $this->prefixRouting($routes, $plugin);

Expand Down
3 changes: 3 additions & 0 deletions plugins/baser-core/src/Controller/AppController.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ public function __construct(
{
parent::__construct($request, $response, $name, $eventManager, $components);

// CSRFトークンの場合は高速化のためここで処理を終了
if(!$request->is('requestview')) return;

$request->getSession()->start();

// インストールされていない場合、トップページにリダイレクトする
Expand Down
7 changes: 6 additions & 1 deletion plugins/baser-core/src/Middleware/BcFrontMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,12 @@ public function process(
RequestHandlerInterface $handler
): ResponseInterface
{
if(!BcUtil::isAdminSystem() && BcUtil::isInstalled()) $request = $this->setCurrent($request);
if(!BcUtil::isAdminSystem()
&& BcUtil::isInstalled()
&& $request->is('requestview')
) {
$request = $this->setCurrent($request);
}
return $handler->handle($request);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
namespace BaserCore\Middleware;

use BaserCore\Utility\BcUtil;
use Cake\Core\Configure;
use Cake\Http\Response;
use Cake\ORM\TableRegistry;
use Psr\Http\Message\ResponseInterface;
Expand Down Expand Up @@ -49,7 +48,10 @@ public function process(
RequestHandlerInterface $handler
): ResponseInterface
{
if ($request->is('admin') || !BcUtil::isInstalled()) {
if ($request->is('admin')
|| !BcUtil::isInstalled()
|| !$request->is('requestview')
) {
return $handler->handle($request);
}
$sites = TableRegistry::getTableLocator()->get('BaserCore.Sites');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,10 @@ public function process(
RequestHandlerInterface $handler
): ResponseInterface
{
if ($request->is('admin') || !BcUtil::isInstalled()) {
if ($request->is('admin')
|| !BcUtil::isInstalled()
|| !$request->is('requestview')
) {
return $handler->handle($request);
}
$sites = \Cake\ORM\TableRegistry::getTableLocator()->get('BaserCore.Sites');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,12 @@ public function process(
RequestHandlerInterface $handler
): ResponseInterface
{
if(BcUtil::isInstalled()) {
$request = $this->addDetectors($request);

if(BcUtil::isInstalled() && $request->is('requestview')) {
$response = $this->redirectIfIsDeviceFile($request);
if($response) return $response;
}
$request = $this->addDetectors($request);

/**
* CGIモード等PHPでJWT認証で必要なAuthorizationヘッダーが取得出来ないできない場合、REDIRECT_HTTP_AUTHORIZATION環境変数より取得する
Expand Down

0 comments on commit 895aec0

Please sign in to comment.