mirror of
https://github.com/grocy/grocy.git
synced 2025-08-20 20:26:42 +00:00
Separate app bootstrapping and routes
This commit is contained in:
47
app.php
Normal file
47
app.php
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use \Psr\Http\Message\ServerRequestInterface as Request;
|
||||||
|
use \Psr\Http\Message\ResponseInterface as Response;
|
||||||
|
|
||||||
|
use \Grocy\Middleware\SessionAuthMiddleware;
|
||||||
|
use \Grocy\Middleware\JsonMiddleware;
|
||||||
|
use \Grocy\Middleware\CliMiddleware;
|
||||||
|
|
||||||
|
use \Grocy\Services\ApplicationService;
|
||||||
|
|
||||||
|
require_once __DIR__ . '/vendor/autoload.php';
|
||||||
|
require_once __DIR__ . '/data/config.php';
|
||||||
|
require_once __DIR__ . '/extensions.php';
|
||||||
|
|
||||||
|
// Setup base application
|
||||||
|
if (PHP_SAPI !== 'cli')
|
||||||
|
{
|
||||||
|
$appContainer = new \Slim\Container([
|
||||||
|
'settings' => [
|
||||||
|
'displayErrorDetails' => true,
|
||||||
|
'determineRouteBeforeAppMiddleware' => true
|
||||||
|
],
|
||||||
|
'view' => function($container)
|
||||||
|
{
|
||||||
|
return new \Slim\Views\Blade(__DIR__ . '/views', __DIR__ . '/data/viewcache');
|
||||||
|
}
|
||||||
|
]);
|
||||||
|
|
||||||
|
$app = new \Slim\App($appContainer);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$app = new \Slim\App();
|
||||||
|
$app->add(\pavlakis\cli\CliRequest::class);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add session handling if this is not a demo installation
|
||||||
|
$applicationService = new ApplicationService();
|
||||||
|
if (!$applicationService->IsDemoInstallation())
|
||||||
|
{
|
||||||
|
$app->add(SessionAuthMiddleware::class);
|
||||||
|
}
|
||||||
|
|
||||||
|
require_once __DIR__ . '/routes.php';
|
||||||
|
|
||||||
|
$app->run();
|
@@ -1,3 +1,3 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
require_once __DIR__ . '/../bootstrap.php';
|
require_once __DIR__ . '/../app.php';
|
||||||
|
@@ -1,47 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
use \Psr\Http\Message\ServerRequestInterface as Request;
|
|
||||||
use \Psr\Http\Message\ResponseInterface as Response;
|
|
||||||
|
|
||||||
use \Grocy\Middleware\SessionAuthMiddleware;
|
|
||||||
use \Grocy\Middleware\JsonMiddleware;
|
|
||||||
use \Grocy\Middleware\CliMiddleware;
|
|
||||||
|
|
||||||
use \Grocy\Services\ApplicationService;
|
|
||||||
|
|
||||||
require_once __DIR__ . '/vendor/autoload.php';
|
|
||||||
require_once __DIR__ . '/data/config.php';
|
|
||||||
require_once __DIR__ . '/extensions.php';
|
|
||||||
|
|
||||||
// Setup base application
|
|
||||||
if (PHP_SAPI !== 'cli')
|
|
||||||
{
|
|
||||||
$appContainer = new \Slim\Container([
|
|
||||||
'settings' => [
|
|
||||||
'displayErrorDetails' => true,
|
|
||||||
'determineRouteBeforeAppMiddleware' => true
|
|
||||||
],
|
|
||||||
'view' => function($container)
|
|
||||||
{
|
|
||||||
return new \Slim\Views\Blade(__DIR__ . '/views', __DIR__ . '/data/viewcache');
|
|
||||||
}
|
|
||||||
]);
|
|
||||||
|
|
||||||
$app = new \Slim\App($appContainer);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$app = new \Slim\App();
|
|
||||||
$app->add(\pavlakis\cli\CliRequest::class);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add session handling if this is not a demo installation
|
|
||||||
$applicationService = new ApplicationService();
|
|
||||||
if (!$applicationService->IsDemoInstallation())
|
|
||||||
{
|
|
||||||
$app->add(SessionAuthMiddleware::class);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Base route
|
// Base route
|
||||||
$app->get('/', 'Grocy\Controllers\LoginController:Root')->setName('root');
|
$app->get('/', 'Grocy\Controllers\LoginController:Root')->setName('root');
|
||||||
|
|
||||||
@@ -110,5 +68,3 @@ $app->group('/cli', function()
|
|||||||
{
|
{
|
||||||
$this->get('/recreatedemo', 'Grocy\Controllers\CliController:RecreateDemo');
|
$this->get('/recreatedemo', 'Grocy\Controllers\CliController:RecreateDemo');
|
||||||
})->add(CliMiddleware::class);
|
})->add(CliMiddleware::class);
|
||||||
|
|
||||||
$app->run();
|
|
Reference in New Issue
Block a user