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可以看到欢迎界面。

配置,在当前文件夹创建一个文件config.lua

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

lapis使用的更多相关文章

  1. luarocks install with lua5.1 and luajit to install lapis

    # in luarocks source directory...git clone https://github.com/archoncap/luarockscd luarocks ./config ...

  2. lapis 项目添加prometheus 监控集成grafana

    操作很简单,主要是进行界面的配置以及prometheus 服务的配置, 可以和https://www.cnblogs.com/rongfengliang/p/10074044.html &&a ...

  3. lapis 项目添加prometheus 监控

      lapis 是基于openresty 扩展的,所以直接将支持prometheus的模块构建进openresty 就可以了 我使用的是nginx-module-vts 模块 环境准备 我已经构建好了 ...

  4. lapis 1.7.0 更好的openresty 版本兼容以及安全数据库支持

    lapis 1.7.0 今年4月2号就发布了,一直没有注意,今天看到changelog就简单的进行了一个 测试(主要是与openresty版本的测试,新变更后边会有) 使用docker-compose ...

  5. lapis docker 运行说明

    1. lapis docker 镜像制作 因为openresty 新版本一个json 库的问题,我们使用的是 openresty:1.11.2.1 基础镜像 FROM openresty/openre ...

  6. lapis 处理接收到的json 数据

     备注:      在restful api 开发过程中,大家一般使用的都是json 格式的数据lapis       在处理json 数据上也是比较方便的   1. 使用的api 说明 local ...

  7. luarocks yum 安装引起的lapis lua 包查找问题(centos7版本)

    备注:     大家在进行lapis 开发的时候有些人比较懒直接使用yum 按照luarocks,之后   使用luarocks 安装lapis 一般来说对于linux 64位的环境都会有些问题(包找 ...

  8. lapis 集成openresty最新版本cjson 问题的解决

    备注:    为了解决安装了lapis.同时又希望使用新版nginx 以及openresty 的特性(stream ...)   1. 解决方法 参考: https://github.com/leaf ...

  9. lapis cockroachdb 数据访问试用

    备注:   cockroachdb 的安装可以参考官方文档,以下实例代码使用的是官方的参考例子   1. 数据库配置 // config.lua 参考: local config = require( ...

  10. lapis 数据库配置

    备注:  目前支持 postgresql .mysql (实际使用大家可以尝试用下tidb.CockroachDB)   1. pg数据库配置 // config.lua local config = ...

随机推荐

  1. 买卖股票的最佳时机 [ leetcode ]

    原题地址:https://leetcode-cn.com/problems/best-time-to-buy-and-sell-stock-ii/description/ 给定一个数组,它的第 i 个 ...

  2. TypeConverter使用

    如下代码, <Window.Resources> <local:Human x:Key="human" Name="Tester1" Chil ...

  3. 51Nod 1081前缀和

    #include <iostream> #include <stdio.h> using namespace std; ]; ]; int main() { int n; ci ...

  4. 知问前端——工具提示UI

    工具提示(tooltip),是一个非常实用的UI.它彻底扩展了HTML中的title属性,让提示更加丰富,更加可控制,全面提升了用户体验. 调用tooltip()方法 在调用tooltip()方法之前 ...

  5. 汕头市队赛 C KMP codeforces B. Image Preview

    汕头市队赛题目传送门 codeforces题目传送门 这道题我的做法是 尝试先往左走然后往右走 或者先往右走然后往左走 然后注意一下枚举顺序就okay啦 #include<cstdio> ...

  6. 扑克牌(cards)

    扑克牌 思路 这题也是二分!! 我们二分有几套牌,然后再去检验是否符合,至于怎么想到的,不要问我,我也不知道 那么我们主要解决的就是check函数 我们将二分的套数和每种牌的数量进行比较,如果该种牌的 ...

  7. bzoj1040 内向树DP

    2013-11-17 08:52 原题传送门http://www.lydsy.com/JudgeOnline/problem.php?id=1040 N个骑士,每个人有一个仇人,那么,每个骑士只有一个 ...

  8. 如何优雅地使用minicom

    minicom简介 安装 minicom是linux下一款常用的串口调试工具.ubuntu环境下,使用如下命令安装 sudo apt-get install minicom 配置 使用前需要进行配置, ...

  9. 命令行工具PathMarker

    一直使用Guake 终端,Guake提供的其中一个功能是快速打开. 大概的意思就是,显示在终端上的数据会经过匹配,如果符合一定的规则,则可以按住ctrl,使用鼠标单击以触发指定操作. 比如对于一个文件 ...

  10. 使用Github官方提供的gitignore过滤Git提交的文件

    https://github.com/github/gitignore 在Gitignore项目主页找到VisualStudio.gitignore 下载后放到自己项目根目录的.vs文件夹提交就可以在 ...