add option for auto detecting asset url

This commit is contained in:
printempw 2016-10-17 09:46:57 +08:00
parent 02fe0c67f1
commit 82ada0930b
3 changed files with 20 additions and 6 deletions

View File

@ -18,10 +18,12 @@ class AppServiceProvider extends ServiceProvider
// replace HTTP_HOST with site url setted in options to prevent CDN source problems // replace HTTP_HOST with site url setted in options to prevent CDN source problems
preg_match('/https?:\/\/([^\/]+)\/?.*/', option('site_url'), $host); preg_match('/https?:\/\/([^\/]+)\/?.*/', option('site_url'), $host);
// check if host is valid if (option('auto_detect_asset_url') == "0") {
if (isset($host[1]) && '' === preg_replace('/(?:^\[)?[a-zA-Z0-9-:\]_]+\.?/', '', $host[1])) { // check if host is valid
$this->app['request']->headers->set('host', $host[1]); if (isset($host[1]) && '' === preg_replace('/(?:^\[)?[a-zA-Z0-9-:\]_]+\.?/', '', $host[1])) {
}; $this->app['request']->headers->set('host', $host[1]);
};
}
} }
/** /**

View File

@ -3,7 +3,7 @@
* @Author: printempw * @Author: printempw
* @Date: 2016-07-29 11:53:11 * @Date: 2016-07-29 11:53:11
* @Last Modified by: printempw * @Last Modified by: printempw
* @Last Modified time: 2016-10-16 20:09:27 * @Last Modified time: 2016-10-17 09:40:16
*/ */
return [ return [
@ -36,5 +36,6 @@ return [
'auto_del_invalid_texture' => '0', 'auto_del_invalid_texture' => '0',
'return_200_when_notfound' => '0', 'return_200_when_notfound' => '0',
'cache_expire_time' => '31536000', 'cache_expire_time' => '31536000',
'max_upload_file_size' => '1024' 'max_upload_file_size' => '1024',
'auto_detect_asset_url' => '1'
]; ];

View File

@ -222,6 +222,17 @@
</td> </td>
</tr> </tr>
<tr>
<td class="key">资源地址
<i class="fa fa-question-circle" title="根据当前 URL 自动加载资源文件。如果出现 CDN 回源问题请关闭" data-toggle="tooltip" data-placement="top"></i>
</td>
<td class="value">
<label for="auto_detect_asset_url">
<input {{ (option('auto_detect_asset_url') == '1') ? 'checked="true"' : '' }} type="checkbox" id="auto_detect_asset_url" name="auto_detect_asset_url" value="1"> 自动判断资源文件地址
</label>
</td>
</tr>
<tr> <tr>
<td class="key">HTTP 响应码</td> <td class="key">HTTP 响应码</td>
<td class="value"> <td class="value">