ActFramework 小貼士 - 得到應用版本

有的項目可能須要前端展現後端應用的版本, 這樣可讓用戶在報告錯誤的時候給出版本信息,幫助定位錯誤.前端

使用 ActFramework 開發應用能夠很方便地提供應用版本信息給前端.nginx

1. 訪問 /~/info 服務

使用 Accept=application/jsonjson

image

Accept 設置爲其餘值後端

image

2. 檢查響應的 Server 頭:

image

當你的應用部署在 nginx 後面的時候, Server 頭被 nginx 佔用了. 這時候你能夠設置 nginx 使用其餘頭來輸出應用版本信息, 例如 X-App-Version:app

server {
  listen          80;
  server_name     mysvc.mycomp.com;

  location / {
    proxy_pass        http://localhost:5460;
    proxy_set_header  X-Real-IP $remote_addr;
    proxy_set_header  X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header  Host $http_host;
    add_header X-App-Version $upstream_http_server; 
  }
}

設置好了以後你就能從響應中經過 X-App-Version (或者你設置的任何名字) 訪問到應用的版本了:code

image

相關文章
相關標籤/搜索