Skip sourcemap requests

This commit is contained in:
Alex Tselegidis 2024-01-29 12:25:46 +01:00
parent b58cbc90d0
commit d64f65e6ae

149
index.php
View file

@ -47,14 +47,14 @@
* *
*/ */
if ( ! file_exists(__DIR__ . '/config.php')) if (!file_exists(__DIR__ . '/config.php')) {
{ die(
die('The root "config.php" file is missing, please copy "config-sample.php" to "config.php" and update it with your server data.'); 'The root "config.php" file is missing, please copy "config-sample.php" to "config.php" and update it with your server data.'
);
} }
require_once __DIR__ . '/config.php'; require_once __DIR__ . '/config.php';
/* /*
*--------------------------------------------------------------- *---------------------------------------------------------------
* COMPOSER AUTOLOAD FILE * COMPOSER AUTOLOAD FILE
@ -65,13 +65,28 @@ require_once __DIR__ . '/config.php';
* *
*/ */
if ( ! file_exists(__DIR__ . '/vendor/autoload.php')) if (!file_exists(__DIR__ . '/vendor/autoload.php')) {
{ die(
die('The "vendor/autoload.php" file is missing, please install the Composer dependencies with "composer install" before using the app.'); 'The "vendor/autoload.php" file is missing, please install the Composer dependencies with "composer install" before using the app.'
);
} }
require_once __DIR__ . '/vendor/autoload.php'; require_once __DIR__ . '/vendor/autoload.php';
/*
*---------------------------------------------------------------
* SKIP SOURCEMAP REQUESTS
*---------------------------------------------------------------
*
* Some vendor files might mistakenly request source map files.
*
*/
if (str_contains($_SERVER['REQUEST_URI'], '.min.js.map')) {
http_response_code(404);
exit();
}
/* /*
*--------------------------------------------------------------- *---------------------------------------------------------------
* APPLICATION ENVIRONMENT * APPLICATION ENVIRONMENT
@ -92,13 +107,10 @@ require_once __DIR__ . '/vendor/autoload.php';
$app_env = getenv('APP_ENV'); $app_env = getenv('APP_ENV');
if ($app_env) if ($app_env) {
{
define('ENVIRONMENT', $app_env); define('ENVIRONMENT', $app_env);
} } else {
else define('ENVIRONMENT', Config::DEBUG_MODE ? 'development' : 'production');
{
define('ENVIRONMENT', (Config::DEBUG_MODE) ? 'development' : 'production');
} }
/* /*
@ -109,8 +121,7 @@ else
* Different environments will require different levels of error reporting. * Different environments will require different levels of error reporting.
* By default development will show errors but testing and live will hide them. * By default development will show errors but testing and live will hide them.
*/ */
switch (ENVIRONMENT) switch (ENVIRONMENT) {
{
case 'development': case 'development':
error_reporting(-1); error_reporting(-1);
ini_set('display_errors', 1); ini_set('display_errors', 1);
@ -119,18 +130,15 @@ switch (ENVIRONMENT)
case 'testing': case 'testing':
case 'production': case 'production':
ini_set('display_errors', 0); ini_set('display_errors', 0);
if (version_compare(PHP_VERSION, '5.3', '>=')) if (version_compare(PHP_VERSION, '5.3', '>=')) {
{
error_reporting(E_ALL & ~E_NOTICE & ~E_DEPRECATED & ~E_STRICT & ~E_USER_NOTICE & ~E_USER_DEPRECATED); error_reporting(E_ALL & ~E_NOTICE & ~E_DEPRECATED & ~E_STRICT & ~E_USER_NOTICE & ~E_USER_DEPRECATED);
} } else {
else
{
error_reporting(E_ALL & ~E_NOTICE & ~E_STRICT & ~E_USER_NOTICE); error_reporting(E_ALL & ~E_NOTICE & ~E_STRICT & ~E_USER_NOTICE);
} }
break; break;
default: default:
header('HTTP/1.1 503 Service Unavailable.', TRUE, 503); header('HTTP/1.1 503 Service Unavailable.', true, 503);
echo 'The application environment is not set correctly.'; echo 'The application environment is not set correctly.';
exit(1); // EXIT_ERROR exit(1); // EXIT_ERROR
} }
@ -177,7 +185,6 @@ $application_folder = 'application';
*/ */
$view_folder = ''; $view_folder = '';
/* /*
* -------------------------------------------------------------------- * --------------------------------------------------------------------
* DEFAULT CONTROLLER * DEFAULT CONTROLLER
@ -207,7 +214,6 @@ $view_folder = '';
// The controller function you wish to be called. // The controller function you wish to be called.
// $routing['function'] = ''; // $routing['function'] = '';
/* /*
* ------------------------------------------------------------------- * -------------------------------------------------------------------
* CUSTOM CONFIG VALUES * CUSTOM CONFIG VALUES
@ -224,7 +230,6 @@ $view_folder = '';
*/ */
// $assign_to_config['name_of_config_item'] = 'value of config item'; // $assign_to_config['name_of_config_item'] = 'value of config item';
// -------------------------------------------------------------------- // --------------------------------------------------------------------
// END OF USER CONFIGURABLE SETTINGS. DO NOT EDIT BELOW THIS LINE // END OF USER CONFIGURABLE SETTINGS. DO NOT EDIT BELOW THIS LINE
// -------------------------------------------------------------------- // --------------------------------------------------------------------
@ -236,30 +241,23 @@ $view_folder = '';
*/ */
// Set the current directory correctly for CLI requests // Set the current directory correctly for CLI requests
if (defined('STDIN')) if (defined('STDIN')) {
{
chdir(dirname(__FILE__)); chdir(dirname(__FILE__));
} }
if (($_temp = realpath($system_path)) !== FALSE) if (($_temp = realpath($system_path)) !== false) {
{
$system_path = $_temp . DIRECTORY_SEPARATOR; $system_path = $_temp . DIRECTORY_SEPARATOR;
} } else {
else
{
// Ensure there's a trailing slash // Ensure there's a trailing slash
$system_path = strtr( $system_path =
rtrim($system_path, '/\\'), strtr(rtrim($system_path, '/\\'), '/\\', DIRECTORY_SEPARATOR . DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR;
'/\\',
DIRECTORY_SEPARATOR . DIRECTORY_SEPARATOR
) . DIRECTORY_SEPARATOR;
} }
// Is the system path correct? // Is the system path correct?
if ( ! is_dir($system_path)) if (!is_dir($system_path)) {
{ header('HTTP/1.1 503 Service Unavailable.', true, 503);
header('HTTP/1.1 503 Service Unavailable.', TRUE, 503); echo 'Your system folder path does not appear to be set correctly. Please open the following file and correct this: ' .
echo 'Your system folder path does not appear to be set correctly. Please open the following file and correct this: ' . pathinfo(__FILE__, PATHINFO_BASENAME); pathinfo(__FILE__, PATHINFO_BASENAME);
exit(3); // EXIT_CONFIG exit(3); // EXIT_CONFIG
} }
@ -281,70 +279,43 @@ define('FCPATH', dirname(__FILE__) . DIRECTORY_SEPARATOR);
define('SYSDIR', basename(BASEPATH)); define('SYSDIR', basename(BASEPATH));
// The path to the "application" directory // The path to the "application" directory
if (is_dir($application_folder)) if (is_dir($application_folder)) {
{ if (($_temp = realpath($application_folder)) !== false) {
if (($_temp = realpath($application_folder)) !== FALSE)
{
$application_folder = $_temp; $application_folder = $_temp;
} } else {
else
{
$application_folder = strtr( $application_folder = strtr(
rtrim($application_folder, '/\\'), rtrim($application_folder, '/\\'),
'/\\', '/\\',
DIRECTORY_SEPARATOR . DIRECTORY_SEPARATOR DIRECTORY_SEPARATOR . DIRECTORY_SEPARATOR,
); );
} }
} } elseif (is_dir(BASEPATH . $application_folder . DIRECTORY_SEPARATOR)) {
elseif (is_dir(BASEPATH . $application_folder . DIRECTORY_SEPARATOR)) $application_folder =
{ BASEPATH . strtr(trim($application_folder, '/\\'), '/\\', DIRECTORY_SEPARATOR . DIRECTORY_SEPARATOR);
$application_folder = BASEPATH . strtr( } else {
trim($application_folder, '/\\'), header('HTTP/1.1 503 Service Unavailable.', true, 503);
'/\\', echo 'Your application folder path does not appear to be set correctly. Please open the following file and correct this: ' .
DIRECTORY_SEPARATOR . DIRECTORY_SEPARATOR self;
);
}
else
{
header('HTTP/1.1 503 Service Unavailable.', TRUE, 503);
echo 'Your application folder path does not appear to be set correctly. Please open the following file and correct this: ' . SELF;
exit(3); // EXIT_CONFIG exit(3); // EXIT_CONFIG
} }
define('APPPATH', $application_folder . DIRECTORY_SEPARATOR); define('APPPATH', $application_folder . DIRECTORY_SEPARATOR);
// The path to the "views" directory // The path to the "views" directory
if ( ! isset($view_folder[0]) && is_dir(APPPATH . 'views' . DIRECTORY_SEPARATOR)) if (!isset($view_folder[0]) && is_dir(APPPATH . 'views' . DIRECTORY_SEPARATOR)) {
{
$view_folder = APPPATH . 'views'; $view_folder = APPPATH . 'views';
} } elseif (is_dir($view_folder)) {
elseif (is_dir($view_folder)) if (($_temp = realpath($view_folder)) !== false) {
{
if (($_temp = realpath($view_folder)) !== FALSE)
{
$view_folder = $_temp; $view_folder = $_temp;
} else {
$view_folder = strtr(rtrim($view_folder, '/\\'), '/\\', DIRECTORY_SEPARATOR . DIRECTORY_SEPARATOR);
} }
else } elseif (is_dir(APPPATH . $view_folder . DIRECTORY_SEPARATOR)) {
{ $view_folder = APPPATH . strtr(trim($view_folder, '/\\'), '/\\', DIRECTORY_SEPARATOR . DIRECTORY_SEPARATOR);
$view_folder = strtr( } else {
rtrim($view_folder, '/\\'), header('HTTP/1.1 503 Service Unavailable.', true, 503);
'/\\', echo 'Your view folder path does not appear to be set correctly. Please open the following file and correct this: ' .
DIRECTORY_SEPARATOR . DIRECTORY_SEPARATOR self;
);
}
}
elseif (is_dir(APPPATH . $view_folder . DIRECTORY_SEPARATOR))
{
$view_folder = APPPATH . strtr(
trim($view_folder, '/\\'),
'/\\',
DIRECTORY_SEPARATOR . DIRECTORY_SEPARATOR
);
}
else
{
header('HTTP/1.1 503 Service Unavailable.', TRUE, 503);
echo 'Your view folder path does not appear to be set correctly. Please open the following file and correct this: ' . SELF;
exit(3); // EXIT_CONFIG exit(3); // EXIT_CONFIG
} }