remove old code, add error middleware and catch all route

This commit is contained in:
Uwe Steinmann 2025-02-21 07:34:24 +01:00
parent 879855536f
commit a44ddc0b94

View File

@ -44,32 +44,9 @@ if(true) {
$containerBuilder = new \DI\ContainerBuilder();
$c = $containerBuilder->build();
/*
$c['notFoundHandler'] = function ($c) use ($settings, $dms) {
return function ($request, $response) use ($c, $settings, $dms) {
$uri = $request->getUri();
if($uri->getBasePath())
$file = $uri->getPath();
else
$file = substr($uri->getPath(), 1);
if(file_exists($file) && is_file($file)) {
$_SERVER['SCRIPT_FILENAME'] = basename($file);
// include($file);
exit;
}
if($request->isXhr()) {
exit;
}
// print_r($request->getUri());
// exit;
return $c['response']
->withStatus(302)
->withHeader('Location', isset($settings->_siteDefaultPage) && strlen($settings->_siteDefaultPage)>0 ? $settings->_httpRoot.$settings->_siteDefaultPage : $settings->_httpRoot."out/out.ViewFolder.php");
};
};
*/
AppFactory::setContainer($c);
$app = AppFactory::create();
/* put lots of data into the container, because if slim instanciates
* a class by itself (with the help from the DI container), it will
* pass the container to the constructor of the instanciated class.
@ -91,12 +68,8 @@ if(true) {
}
}
$app->get('/', function($request, $response) {
return $response
->withHeader('Location', '/out/out.ViewFolder.php')
->withStatus(302);
$app->addErrorMiddleware(false, true, true);
});
if(isset($GLOBALS['SEEDDMS_HOOKS']['initDMS'])) {
foreach($GLOBALS['SEEDDMS_HOOKS']['initDMS'] as $hookObj) {
if (method_exists($hookObj, 'addRoute')) {
@ -107,20 +80,13 @@ if(true) {
}
}
/*
$app->get('/out/[{path:.*}]', function($request, $response, $path = null) use ($app) {
$uri = $request->getUri();
if($uri->getBasePath())
$file = $uri->getPath();
else
$file = substr($uri->getPath(), 1);
if(file_exists($file) && is_file($file)) {
$_SERVER['SCRIPT_FILENAME'] = basename($file);
include($file);
exit;
}
/* Catch all route */
$app->get('/{path:.*}', function($request, $response) {
return $response
->withHeader('Location', '/out/out.ViewFolder.php')
->withStatus(302);
});
*/
$app->run();
} else {