已提交PR( https://github.com/walkor/webman/pull/384 ) ,看看大佬評估下,是否能合進去
重寫path這個在nginx里就一句配置的事情,就不在webman做了。
如果有需要webman重寫path,像你pr那樣改下 support\Request.php 類就好了
嗯嗯,好的。我只是搜索了一下,看見thinkphp那么轉(zhuǎn)過來的基本上都遇到了這個問題,這個應(yīng)用不多是在nginx里是一句配置的事,但在整個公司的統(tǒng)一研發(fā)規(guī)范上的確是很方便的一件事,它使我們在docker上作為統(tǒng)一的開發(fā)環(huán)境的時候,不需要添加另外的容器,實現(xiàn)了功能,同時在生產(chǎn)環(huán)境的時候,不需要運維多去專注轉(zhuǎn)發(fā)的配置問題,針對復(fù)雜的集群項目,一套代碼可能針對了十幾個端的應(yīng)用,所以我會覺的,在配置指向的時候就實現(xiàn)了轉(zhuǎn)發(fā)功能,而不再特意迭加一層nginx是非常棒的。
雖然不合并到webman,但后面tp轉(zhuǎn)過來的同行有需要的可以去PR( https://github.com/walkor/webman/pull/384/commits/cfa8016945113eff2fc55b31ca992dcf415e045f )中自取吧。
1、在support\Request.php添加
//重寫獲取path用于多路由
public function path()
{
if (!isset($this->_data['path'])) {
if(config('domain.enable', false)){
//如果開啟了域名路由
$uri = $this->uri();
$bind = config('domain.bind', []);
$domain = $this->host(true);
if(isset($bind[$domain])) {
$uri = '/' . $bind[$domain] . $uri;
}
}
$this->_data['path'] = (string)\parse_url($uri, PHP_URL_PATH);
}
return $this->_data['path'];
}
2、添加配置文件 config/domain.php
<?php
return [
//是否開啟域名路由
'enable' => true,
// 多應(yīng)用綁定關(guān)系
'bind' => [
// 'abc.com' => '', // 不屬于任何應(yīng)用
'abcd' => 'touser', // 綁定到touser應(yīng)用
'abce' => 'toadmin', // 綁定到toadmin應(yīng)用
]
];