summaryrefslogtreecommitdiffstats
path: root/openresty-ext/src/assembly/resources/openresty/nginx/luaext/msb.lua
diff options
context:
space:
mode:
Diffstat (limited to 'openresty-ext/src/assembly/resources/openresty/nginx/luaext/msb.lua')
-rw-r--r--openresty-ext/src/assembly/resources/openresty/nginx/luaext/msb.lua54
1 files changed, 51 insertions, 3 deletions
diff --git a/openresty-ext/src/assembly/resources/openresty/nginx/luaext/msb.lua b/openresty-ext/src/assembly/resources/openresty/nginx/luaext/msb.lua
index f791bdb..c454173 100644
--- a/openresty-ext/src/assembly/resources/openresty/nginx/luaext/msb.lua
+++ b/openresty-ext/src/assembly/resources/openresty/nginx/luaext/msb.lua
@@ -1,6 +1,6 @@
--[[
- Copyright (C) 2016 ZTE, Inc. and others. All rights reserved. (ZTE)
+ Copyright (C) 2017-2018 ZTE, Inc. and others. All rights reserved. (ZTE)
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
@@ -22,9 +22,11 @@ _M._DESCRIPTION = 'msb plugins controller'
local default_conf = require('plugins.config_default')
local custom_conf = require('plugins.config_custom')
+local msb_router= require('core.router')
local table_insert = table.insert
local string_find = string.find
local str_low = string.lower
+local ngx_var = ngx.var
--- Borrowed from Kong
--- Try to load a module.
@@ -64,7 +66,7 @@ function _M.load_plugins()
if not loaded then
error("The following plugin has been enabled in the configuration but it is not installed on the system: "..v)
end
- ngx.log(ngx.DEBUG, "Loading plugin: "..v)
+ ngx.log(ngx.WARN, "Loading plugin: "..v)
table_insert(plugins, {
name = v,
handler = plugin_handler_mod()
@@ -73,6 +75,52 @@ function _M.load_plugins()
package.loaded.plugins = plugins
end
+function _M.filter_websocket_req()
+ local http_upgrade = ngx_var.http_upgrade
+ if http_upgrade and str_low(http_upgrade) == "websocket" then
+ --ngx.log(ngx.ERR, "Websocket request and redirect to @commonwebsocket")
+ return ngx.exec("@websocket");
+ end
+end
+
+function _M.route()
+ msb_router.execute(ngx_var.server_port,"ROUTER")
+end
+
+local function prepare_route()
+ local uri = ngx_var.uri
+ local m, err = ngx.re.match(uri, "^/(api|admin|apijson)(/[Vv]\\d+(?:\\.\\d+)*)?/([^/]+)(/[Vv]\\d+(?:\\.\\d+)*)?(.*)", "o")
+ if m then
+ ngx_var.svc_type = m[1]
+ ngx_var.svc_name = m[3]
+ ngx_var.svc_version1 = m[2] or ""
+ ngx_var.svc_version2 = m[4] or ""
+ ngx_var.req_res = m[5]
+ return
+ end
+ local m, err = ngx.re.match(uri, "^/iui/([^/]+)(.*)", "o")
+ if m then
+ ngx_var.svc_type = "iui"
+ ngx_var.svc_name = m[1]
+ ngx_var.req_res = m[2]
+ return
+ end
+ ngx_var.svc_type = "custom"
+ return
+end
+
+function _M.external_route(server_port,system_tag)
+ if not server_port or not system_tag then
+ local err = "server_port and system_tag are required while routing!"
+ ngx.log(ngx.WARN, ngx.var.request_id.." "..err)
+ ngx.status = ngx.HTTP_BAD_GATEWAY
+ ngx.print(err)
+ return ngx.exit(ngx.status)
+ end
+ prepare_route()
+ msb_router.execute(server_port,system_tag)
+end
+
function _M.access()
local plugins = package.loaded.plugins
for _, plugin in ipairs(plugins) do
@@ -87,4 +135,4 @@ function _M.header_filter()
end
end
-return _M \ No newline at end of file
+return _M