Skip to content
This repository has been archived by the owner on Dec 11, 2020. It is now read-only.

Commit

Permalink
Merge pull request #56 from APItools/smart-router
Browse files Browse the repository at this point in the history
introduce smart router on port 8080
  • Loading branch information
mikz committed Oct 14, 2015
2 parents b062cc5 + 9bcca49 commit 229dc0f
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
1 change: 1 addition & 0 deletions config/dev.conf
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ http {

lua_package_path ";;./lua/?.lua;";

include router.conf;
include no_cache.conf;
include shared_dict.conf;
include global.conf;
Expand Down
14 changes: 14 additions & 0 deletions config/router.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
server {
listen 8080;
ignore_invalid_headers off;

location / {
set $port "7071";

proxy_set_header Host $http_host;
proxy_set_header Connection $http_connection;
proxy_pass http://127.0.0.1:$port;

access_by_lua_file 'lua/apps/router.lua';
}
}
7 changes: 7 additions & 0 deletions lua/apps/router.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
local CONTAINS_DASH = "^(.*)%-([^.]+)"

if string.match(ngx.var.http_host, CONTAINS_DASH) then
ngx.var.port = 10002
else
ngx.var.port = 7071
end

0 comments on commit 229dc0f

Please sign in to comment.