lapis:
http://leafo.net/lapis/ 官网安装方式依赖lua-cjson,但是已经安装了openresty的可能会报错。
解决方法,使用下面issue中的luarocks install lua-cjson2
https://github.com/leafo/lapis/issues/539
lapis提供lua和moonscript两种代码。
默认生成moonscript脚本,增加--lua这个flag可以生成lua的脚本。包含框架的四个基本的文件。
lapis new --lua
如果安装了openresty,使用
lapis server
打开http://localhost:8080
可以看到欢迎界面。
local config = require("lapis.config")
config("development", {
port = 9090
})
启动之后就端口就改成了9090端口。
创建一个views的文件夹,里面放一个文件index.etlua,内容如下:
<h1>Hello world</h1>
<p>Welcome to my page</p>
lapis将会将index.etlua文件内容解析输出为html网页格式。需要使用app:enable("etlua")
来让lapis解析对应的etlua文件为html。
local respond_to = require ("lapis.application").respond_to
app:enable("etlua")
local blm_hc_status = require "controllers.blm_hc_status"
app:match("/hello", respond_to(blm_hc_status))
新建的文件夹controllers文件夹下面,创建一个文件,因为是match,里面可以写四种方法,访问http://localhost:9090/hello
local db = require("lapis.db")
local mt = {}
function mt:GET()
local res = db.query("select * from tb_hc_status")
self.services = res
return { render = "index" }
end
return mt
手机扫一扫
移动阅读更方便
你可能感兴趣的文章