Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: sumory/lor
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v0.3.4
Choose a base ref
...
head repository: sumory/lor
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref
  • 19 commits
  • 12 files changed
  • 7 contributors

Commits on May 17, 2018

  1. Update directive.lua

    生成的nginx.conf模板有两个默认路径,即:lua_package_path "./app/?.lua;./?.lua;/usr/local/lor/?.lua;;;;";
    wuyachao authored May 17, 2018
    Copy the full SHA
    ffa4cc7 View commit details
  2. Merge pull request #75 from wuyachao/patch-1

    remove redundant semicolon for lua_package_cpath
    ms2008 authored May 17, 2018
    Copy the full SHA
    d142e96 View commit details

Commits on Oct 8, 2018

  1. Update node.lua

    compatible with before the ngx.1.9.11
    noname007 authored Oct 8, 2018
    Copy the full SHA
    f49fb6d View commit details

Commits on Aug 29, 2019

  1. Copy the full SHA
    859a036 View commit details
  2. Merge pull request #91 from sugelalin/hotfix_fix_lord_command_warning

    去掉执行lord命令时,产生的warning报警信息
    ms2008 authored Aug 29, 2019
    Copy the full SHA
    a9be518 View commit details

Commits on Sep 1, 2019

  1. minor code style fixes

    ms2008 committed Sep 1, 2019
    1
    Copy the full SHA
    f4596a9 View commit details
  2. Merge pull request #92 from sumory/fix-style

    minor code style fixes
    sumory authored Sep 1, 2019
    Copy the full SHA
    e0acddd View commit details

Commits on Sep 2, 2019

  1. Copy the full SHA
    52a7998 View commit details

Commits on Sep 18, 2019

  1. Merge pull request #93 from sumory/improve-reload

    improved reload form by kill command instead of signaller notice
    sumory authored Sep 18, 2019
    Copy the full SHA
    f750a05 View commit details

Commits on Nov 11, 2019

  1. Copy the full SHA
    d8a692f View commit details

Commits on Jan 16, 2020

  1. Update README.md

    xerox-xeon authored Jan 16, 2020
    Copy the full SHA
    35b6ef5 View commit details

Commits on Feb 15, 2020

  1. typo for (

    hanxi authored Feb 15, 2020
    Copy the full SHA
    3b14106 View commit details

Commits on Feb 16, 2020

  1. update opm package version

    hanxi authored Feb 16, 2020
    Copy the full SHA
    a13e115 View commit details

Commits on Feb 17, 2020

  1. fix reload use kill

    hanxi committed Feb 17, 2020
    Copy the full SHA
    48888d6 View commit details

Commits on Feb 18, 2020

  1. Merge pull request #100 from hanxi/patch-2

    fix a typo
    ms2008 authored Feb 18, 2020
    Copy the full SHA
    17d0f54 View commit details
  2. Merge pull request #101 from hanxi/patch-3

    update opm package version
    ms2008 authored Feb 18, 2020
    Copy the full SHA
    5bdc387 View commit details
  3. Merge pull request #95 from sumory/fix-uri-match

    fix exception when handling percent character in uri
    sumory authored Feb 18, 2020
    Copy the full SHA
    f79b5ea View commit details
  4. Merge pull request #102 from hanxi/patch-4

    fix typo use kill
    sumory authored Feb 18, 2020
    Copy the full SHA
    87e6c35 View commit details

Commits on Jan 4, 2022

  1. Merge pull request #98 from lifeblood/patch-2

    docs: add new use case
    ms2008 authored Jan 4, 2022
    Copy the full SHA
    6be87db View commit details
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -23,6 +23,7 @@ app:run()

- [lor-example](https://github.com/lorlabs/lor-example)
- [openresty-china](https://github.com/sumory/openresty-china)
- [lua-redis-admin](https://github.com/lifeblood/lua-redis-admin)


## Installation
12 changes: 2 additions & 10 deletions bin/scaffold/generator.lua
Original file line number Diff line number Diff line change
@@ -415,7 +415,6 @@ return userRouter
]]



local middleware_tpl = [[
### 自定义插件目录(define your own middleware)
@@ -482,9 +481,7 @@ local function nginx_conf_content()
local nginx_conf_template = ngx_conf_template.get_ngx_conf_template()

-- append notice
nginx_conf_template = [[
#generated by `lor framework`
]] .. nginx_conf_template
nginx_conf_template = [[# generated by `lor framework`]] .. nginx_conf_template

local match = {}
local tmp = 1
@@ -576,11 +573,10 @@ fi
mkdir -p logs & mkdir -p tmp
echo "reload lor application with profile: "${PROFILE}
nginx -s reload -p `pwd`/ -c conf/nginx-${PROFILE}.conf
kill -HUP $(cat `pwd`/${PROFILE}-nginx.pid)
]]



local Generator = {}

Generator.files = {
@@ -622,7 +618,3 @@ function Generator.create_files(parent)
end

return Generator




4 changes: 1 addition & 3 deletions bin/scaffold/launcher.lua
Original file line number Diff line number Diff line change
@@ -5,7 +5,6 @@ local ngx_handle = require 'bin.scaffold.nginx.handle'
local ngx_config = require 'bin.scaffold.nginx.config'
local ngx_conf_template = require 'bin.scaffold.nginx.conf_template'


local Lor = {}

function Lor.nginx_conf_content()
@@ -35,7 +34,7 @@ function Lor.nginx_conf_content()
return nginx_conf_template
end

function new_handler()
local function new_handler()
local necessary_dirs ={ -- runtime nginx conf/pid/logs dir
tmp = 'tmp',
logs = 'logs'
@@ -67,7 +66,6 @@ function Lor.start()
end
end


function Lor.stop()
local env = ogetenv("LOR_ENV") or 'dev'

4 changes: 2 additions & 2 deletions bin/scaffold/nginx/conf_template.lua
Original file line number Diff line number Diff line change
@@ -30,7 +30,7 @@ http {
# Error log
error_log logs/{{LOR_ENV}}-error.log;
# this variable is for view renderlua-resty-template)
# this variable is for view render(lua-resty-template)
set $template_root '';
location /static {
@@ -41,7 +41,7 @@ http {
{{CONTENT_BY_LUA_FILE}}
}
}
]]
]]
end

return _M
56 changes: 27 additions & 29 deletions bin/scaffold/nginx/config.lua
Original file line number Diff line number Diff line change
@@ -5,12 +5,12 @@ local app_run_env = ogetenv("LOR_ENV") or 'dev'

local lor_ngx_conf = {}
lor_ngx_conf.common = { -- directives
LOR_ENV = app_run_env,
-- INIT_BY_LUA_FILE = './app/nginx/init.lua',
-- LUA_PACKAGE_PATH = '',
-- LUA_PACKAGE_CPATH = '',
CONTENT_BY_LUA_FILE = './app/main.lua',
STATIC_FILE_DIRECTORY = './app/static'
LOR_ENV = app_run_env,
-- INIT_BY_LUA_FILE = './app/nginx/init.lua',
-- LUA_PACKAGE_PATH = '',
-- LUA_PACKAGE_CPATH = '',
CONTENT_BY_LUA_FILE = './app/main.lua',
STATIC_FILE_DIRECTORY = './app/static'
}

lor_ngx_conf.env = {}
@@ -30,40 +30,38 @@ lor_ngx_conf.env.prod = {
}

local function getNgxConf(conf_arr)
if conf_arr['common'] ~= nil then
local common_conf = conf_arr['common']
local env_conf = conf_arr['env'][app_run_env]
for directive, info in pairs(common_conf) do
env_conf[directive] = info
end
return env_conf
elseif conf_arr['env'] ~= nil then
return conf_arr['env'][app_run_env]
end
return {}
if conf_arr['common'] ~= nil then
local common_conf = conf_arr['common']
local env_conf = conf_arr['env'][app_run_env]
for directive, info in pairs(common_conf) do
env_conf[directive] = info
end
return env_conf
elseif conf_arr['env'] ~= nil then
return conf_arr['env'][app_run_env]
end
return {}
end

local function buildConf()
local sys_ngx_conf = getNgxConf(lor_ngx_conf)
return sys_ngx_conf
local sys_ngx_conf = getNgxConf(lor_ngx_conf)
return sys_ngx_conf
end


local ngx_directive_handle = require('bin.scaffold.nginx.directive'):new(app_run_env)
local ngx_directives = ngx_directive_handle:directiveSets()
local ngx_run_conf = buildConf()

local LorNgxConf = {}
for directive, func in pairs(ngx_directives) do
if type(func) == 'function' then
local func_rs = func(ngx_directive_handle, ngx_run_conf[directive])
if func_rs ~= false then
LorNgxConf[directive] = func_rs
end
else
LorNgxConf[directive] = ngx_run_conf[directive]
end
if type(func) == 'function' then
local func_rs = func(ngx_directive_handle, ngx_run_conf[directive])
if func_rs ~= false then
LorNgxConf[directive] = func_rs
end
else
LorNgxConf[directive] = ngx_run_conf[directive]
end
end

return LorNgxConf

13 changes: 6 additions & 7 deletions bin/scaffold/nginx/directive.lua
Original file line number Diff line number Diff line change
@@ -3,7 +3,6 @@
package.path = './app/?.lua;' .. package.path
package.cpath = './app/library/?.so;' .. package.cpath


local Directive = {}

function Directive:new(env)
@@ -27,7 +26,7 @@ end
function Directive:luaPackageCpath(lua_cpath)
local path = package.cpath
if lua_cpath ~= nil then path = lua_cpath .. path end
local res = [[lua_package_cpath "]] .. path .. [[;;";]]
local res = [[lua_package_cpath "]] .. path .. [[";]]
return res
end

@@ -52,13 +51,13 @@ function Directive:luaSharedDict( lua_lib )
end

function Directive:initByLua(lua_lib)
if lua_lib == nil then return '' end
if lua_lib == nil then return '' end
local res = [[init_by_lua require(']] .. lua_lib .. [['):run();]]
return res
end

function Directive:initByLuaFile(lua_file)
if lua_file == nil then return '' end
if lua_file == nil then return '' end
local res = [[init_by_lua_file ]] .. lua_file .. [[;]]
return res
end
@@ -100,13 +99,13 @@ function Directive:rewriteByLuaFile(lua_file)
end

function Directive:accessByLua(lua_lib)
if lua_lib == nil then return '' end
if lua_lib == nil then return '' end
local res = [[access_by_lua require(']] .. lua_lib .. [['):run();]]
return res
end

function Directive:accessByLuaFile(lua_file)
if lua_file == nil then return '' end
if lua_file == nil then return '' end
local res = [[access_by_lua_file ]] .. lua_file .. [[;]]
return res
end
@@ -202,4 +201,4 @@ function Directive:directiveSets()
}
end

return Directive
return Directive
1 change: 0 additions & 1 deletion bin/scaffold/nginx/handle.lua
Original file line number Diff line number Diff line change
@@ -72,5 +72,4 @@ function NginxHandle:reload(env)
return reload_nginx(env, self.nginx_conf_file_path)
end


return NginxHandle
5 changes: 1 addition & 4 deletions bin/scaffold/utils.lua
Original file line number Diff line number Diff line change
@@ -13,12 +13,10 @@ function Utils.read_file(file_path)
return content
end


local function require_module(module_name)
return require(module_name)
end


-- try to require
function Utils.try_require(module_name, default)
local ok, module_or_err = pcall(require_module, module_name)
@@ -32,7 +30,6 @@ function Utils.try_require(module_name, default)
end
end


function Utils.dirname(str)
if str:match(".-/.-") then
local name = string.gsub(str, "(.*/)(.*)", "%1")
@@ -42,4 +39,4 @@ function Utils.dirname(str)
end
end

return Utils
return Utils
2 changes: 1 addition & 1 deletion dist.ini
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = lor
abstract = A fast and minimalist web framework based on OpenResty.
version = 0.3.3
version = 0.3.4
author = Sumory Wu (@sumory)
is_original = yes
license = mit
4 changes: 2 additions & 2 deletions lib/lor/lib/node.lua
Original file line number Diff line number Diff line change
@@ -17,13 +17,13 @@ local node_count = 0
local function gen_node_id()
local prefix = "node-"
local worker_part = "dw"
if ngx and ngx.worker then
if ngx and ngx.worker and ngx.worker.id() then
worker_part = ngx.worker.id()
end
node_count = node_count + 1 -- simply count for lua vm level
local unique_part = node_count
local random_part = utils.random()
node_id = prefix .. worker_part .. "-" .. unique_part .. "-" .. random_part
local node_id = prefix .. worker_part .. "-" .. unique_part .. "-" .. random_part
return node_id
end

2 changes: 1 addition & 1 deletion lib/lor/lib/trie.lua
Original file line number Diff line number Diff line change
@@ -20,7 +20,7 @@ local valid_segment_tip = "valid path should only contains: [A-Za-z0-9._%-~]"


local function check_segment(segment)
local tmp = string_gsub(segment, "([A-Za-z0-9._%-~]+)", "")
local tmp = string_gsub(segment, "([A-Za-z0-9._%%-~]+)", "")
if tmp ~= "" then
return false
end
11 changes: 10 additions & 1 deletion spec/cases/uri_char_spec.lua
Original file line number Diff line number Diff line change
@@ -41,5 +41,14 @@ describe("uri should support `-`", function()
app:handle(req, res)
assert.is.equals(2, flag)
end)


it("test case 3", function()
req.path = "/a_-b-%"
req.method = "get"
app:get("/a_-b-%", function(req, res, next)
flag = 3
end)
app:handle(req, res)
assert.is.equals(3, flag)
end)
end)