2015-10-26 28 views
2

我想下面的路由的行爲:uWSGI路由規則重寫靜態文件

  • 存在於webapp/static/應該被路由到該文件
  • 任何其他道路不以/auth開始的任何路徑或/api應路由到webapp/static/pages/index.html
  • 將剩餘請求路由到我的uwsgi應用程序。

我有以下uWSGI配置:

[uwsgi] 
http-socket = :$(PORT) 
master = true 
processes = 4 
die-on-term = true 
module = webapp:app 
memory-report = true 

;HSTS 
route-host = ^localhost:(?:[0-9]+)$ goto:localhost 
route-if-not = equal:${HTTP_X_FORWARDED_PROTO};https redirect-permanent:https://${HTTP_HOST}${REQUEST_URI} 
route-if = equal:${HTTP_X_FORWARDED_PROTO};https addheader:Strict-Transport-Security: max-age=31536000; preload 

route-label = localhost 
check-static = %v/webapp/static/ 
route = ^(/?|/(?!(auth.*|api.*))(.*))$ static:%v/webapp/static/pages/index.html 

的問題是,最終的途徑規則重寫靜態文件處理程序,即使我更改其順序..以前,我用正則表達式^/?$只發送請求到/到索引頁面,該頁面完美運行,所以它必須與正則表達式的工作方式有關。

回答

0

可能靜態規則是在正則表達式之後進行評估的。您使用的正則表達式也匹配/webapp/static路徑,因此我們也需要排除該路徑。

嘗試修改正則表達式規則是這樣的:

# I removed also unused matching groups and append '/' to the exclude path 
route = ^(?:/?|/(?!(?:auth|api|webapp/static)/).*)$ static:%v/webapp/static/pages/index.html