3 Star 2 Fork 0

sumory / lor

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

Lor

中文 English

https://travis-ci.org/sumory/lor.svg?branch=master

Lor是一个运行在OpenResty上的基于Lua编写的Web框架.

  • 路由采用Sinatra风格,Sinatra是Ruby小而精的web框架.
  • API基本采用了Express的思路和设计,Node.js跨界开发者可以很快上手.
  • 支持插件(middleware),路由可分组,路由匹配支持strin或正则模式.
  • lor以后会保持核心足够精简,扩展功能依赖middleware来实现. lor本身也是基于middleware构建的.
  • 推荐使用lor作为HTTP API Server,lor也已支持session/cookie/html template等功能.
  • 简单示例项目lor-example
  • 全站示例项目openresty-china

当前版本:v0.1.0

文档

http://lor.sumory.com

快速开始

特别注意: 在使用lor之前请首先确保OpenResty和luajit已安装,并配置到环境变量中。即在命令行直接输入nginx -vluajit -v能正确输出。

一个简单示例,更复杂的示例或项目模板请使用lord命令生成:

local lor = require("lor.index")
local app = lor()

app:get("/", function(req, res, next)
    res:send("hello world!")
end)

-- 路由示例: 匹配/query/123?foo=bar
app:get("/query/:id", function(req, res, next)
    local foo = req.query.foo
    local path_id = req.params.id
    res:json({
        foo = foo,
        id = path_id
    })
end)

-- 404 error
app:use(function(req, res, next)
    if req:is_found() ~= true then
        res:status(404):send("sorry, not found.")
    end
end)

-- 错误处理插件,可根据需要定义多个
app:erroruse(function(err, req, res, next)
    -- err是错误对象
    res:status(500):send("服务器内发生未知错误")
end)

安装

使用install.sh安装lor框架,强烈建议在使用install.sh安装前阅读该脚本代码。

# 把lor安装到/opt/lua/lor目录下
sh install.sh /opt/lua
# 或者安装到默认目录/usr/local/lor下
sh install.sh

执行以上命令后lor的命令行工具lord就被安装在了/usr/local/bin下, 通过which lord查看:

$ which lord
/usr/local/bin/lord

lor的运行时包安装在了指定目录下, 若安装在/opt/lua/lor,通过ll /opt/lua/lor查看:

$ ll /opt/lua/lor
total 56
drwxr-xr-x  14 root  wheel   476B  1 22 01:18 .
drwxrwxrwt  14 root  wheel   476B  1 22 01:18 ..
-rw-r--r--   1 root  wheel     0B  1 19 23:48 CHANGELOG.md
-rw-r--r--   1 root  wheel   1.0K  1 19 23:48 LICENSE
-rw-r--r--   1 root  wheel     0B  1 19 23:48 Makefile
-rw-r--r--   1 root  wheel   1.9K  1 21 20:59 README-zh.md
-rw-r--r--   1 root  wheel   870B  1 21 20:59 README.md
drwxr-xr-x   4 root  wheel   136B  1 22 00:06 bin
-rw-r--r--   1 root  wheel   1.0K  1 21 22:37 install.sh
drwxr-xr-x   4 root  wheel   136B  1 21 22:40 lor

至此, lor框架已经安装完毕,接下来使用lord命令行工具快速开始一个项目骨架.

使用

$ lord -h
lor ${version}, a Lua web framework based on OpenResty.

Usage: lor COMMAND [OPTIONS]

Commands:
 new [name]             Create a new application
 start                  Starts the server
 stop                   Stops the server
 restart                Restart the server
 version                Show version of lor
 help                   Show help tips

执行lord new lor_demo,则会生成一个名为lor_demo的示例项目,然后执行:

cd lor_demo
lord start

之后访问http://localhost:8888/,即可。

更多使用方法,请参考test测试用例。

讨论交流

目前有一个QQ群用于在线讨论: 522410959

License

MIT

The MIT License (MIT) Copyright (c) 2016 sumory.wu Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

a fast, minimalist web framework for lua based on OpenResty 展开 收起
Lua
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
Lua
1
https://gitee.com/sumory/lor.git
git@gitee.com:sumory/lor.git
sumory
lor
lor
master

搜索帮助