use methods from UrlGenerator to set root url & schema

This commit is contained in:
printempw 2016-12-16 22:13:41 +08:00
parent 011b6e6e04
commit 28a66cba18
3 changed files with 14 additions and 9 deletions

View File

@ -67,9 +67,10 @@ class AdminController extends Controller
$_POST['site_url'] = substr($_POST['site_url'], 0, -1);
});
$cache = Option::form('cache', '缓存相关配置', function($form)
$cache = Option::form('cache', '资源文件配置', function($form)
{
$form->checkbox('auto_detect_asset_url', '资源地址', '自动判断资源文件地址')->hint('根据当前 URL 自动加载资源文件。如果出现 CDN 回源问题请关闭');
$form->checkbox('force_ssl', '强制 SSL', '强制使用 HTTPS 协议加载资源')->hint('请确认 SSL 可用后再开启');
$form->checkbox('auto_detect_asset_url', '资源地址', '自动判断资源文件地址')->hint('根据当前 URL 自动加载资源文件,如果关闭则将根据「站点地址」填写的内容加载。如果出现 CDN 回源问题请关闭');
$form->checkbox('return_200_when_notfound', 'HTTP 响应码', '请求不存在的角色时返回 200 而不是 404');
$form->text('cache_expire_time', '缓存失效时间')->hint('秒数86400 = 一天31536000 = 一年');

View File

@ -19,13 +19,16 @@ class AppServiceProvider extends ServiceProvider
public function boot()
{
// replace HTTP_HOST with site url setted in options to prevent CDN source problems
preg_match('/https?:\/\/([^\/]+)\/?.*/', option('site_url'), $host);
if (!option('auto_detect_asset_url')) {
// check if host is valid
if (isset($host[1]) && '' === preg_replace('/(?:^\[)?[a-zA-Z0-9-:\]_]+\.?/', '', $host[1])) {
$this->app['request']->headers->set('host', $host[1]);
};
$rootUrl = option('site_url');
if ($this->app['url']->isValidUrl($rootUrl)) {
$this->app['url']->forceRootUrl($rootUrl);
}
}
if (option('force_ssl')) {
$this->app['url']->forceSchema('https');
}
Event::listen(Events\RenderingHeader::class, function($event) {

View File

@ -3,7 +3,7 @@
* @Author: printempw
* @Date: 2016-07-29 11:53:11
* @Last Modified by: printempw
* @Last Modified time: 2016-12-11 22:42:05
* @Last Modified time: 2016-12-16 22:14:18
*/
return [
@ -35,6 +35,7 @@ return [
'return_200_when_notfound' => '0',
'cache_expire_time' => '31536000',
'max_upload_file_size' => '1024',
'force_ssl' => '0',
'auto_detect_asset_url' => '1',
'plugins_enabled' => ''
];