74 lines
2.0 KiB
PHP
74 lines
2.0 KiB
PHP
<?php
|
||
/**
|
||
* Front controller
|
||
*
|
||
* PHP version 7.0
|
||
*/
|
||
/**
|
||
* Composer
|
||
*/
|
||
|
||
require dirname(__DIR__) . '/vendor/autoload.php';
|
||
require dirname(__DIR__) . '/App/Config.php';
|
||
|
||
|
||
/**
|
||
* Error and Exception handling
|
||
*/
|
||
if($_SERVER['HTTP_HOST'] == '127.0.0.1'){
|
||
error_reporting(E_ALL);
|
||
set_error_handler('Core\Error::errorHandler');
|
||
set_exception_handler('Core\Error::exceptionHandler');
|
||
}else{
|
||
error_reporting(0);
|
||
set_error_handler('Core\Error::errorHandlerNone');
|
||
set_exception_handler('Core\Error::exceptionHandlerNone');
|
||
}
|
||
|
||
/**
|
||
* Routing
|
||
*/
|
||
$router = new Core\Router();
|
||
// Add the routes
|
||
$router->add('', ['controller' => 'Home', 'action' => 'index']);
|
||
$router->add('{controller}/{action}');
|
||
$router->add('{controller}/{action}/{id:.+}');
|
||
if($_SERVER['HTTP_HOST'] == '127.0.0.1'){
|
||
$router->AddPrefix(\App\Config::ROUTE_PREFIX_DEV);
|
||
\App\Config::$DEBUG = true;
|
||
}
|
||
else{
|
||
$router->AddPrefix(\App\Config::ROUTE_PREFIX);
|
||
}
|
||
if($_SERVER['HTTP_HOST'] == '192.168.3.100'){
|
||
$router->AddPrefix(\App\Config::ROUTE_PREFIX_DEV);
|
||
\App\Config::$DEBUG = true;
|
||
}
|
||
if($_SERVER['HTTP_HOST'] == '117.50.176.114'){
|
||
$router->AddPrefix("/wapi/");
|
||
//\App\Config::$DEBUG = true;
|
||
}
|
||
|
||
|
||
|
||
try{
|
||
//for prefight request
|
||
if($_SERVER['REQUEST_METHOD'] == 'OPTIONS'){
|
||
header('Access-Control-Allow-Origin:*');
|
||
header('Access-Control-Allow-Methods:OPTIONS, GET, POST'); // 允许option,get,post请求
|
||
header('Access-Control-Allow-Headers:x-requested-with'); // 允许x-requested-with请求头
|
||
header('Access-Control-Allow-Headers:content-type,x-ijt'); // 允许x-requested-with请求头
|
||
//print "";
|
||
return;
|
||
}else{
|
||
//print_r($_SERVER['REQUEST_URI'],\App\Config::ROUTE_PREFIX_DEV);
|
||
$router->dispatch($_SERVER['REQUEST_URI']);
|
||
}
|
||
}catch (Exception $exception){
|
||
echo "<pre>";
|
||
echo $_SERVER['REQUEST_URI'] . " ".$_SERVER['HTTP_HOST']." ". \App\Config::ROUTE_PREFIX;
|
||
echo $exception;
|
||
echo "</pre>";
|
||
}
|
||
|