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. hdu 3473 (划分树)2

    Minimum Sum Time Limit: 16000/8000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Tota ...

  2. HDU 多校对抗 F Naive Operations

    Naive Operations Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 502768/502768 K (Java/Other ...

  3. sysctl -P net.bridge.bridge-nf-call-ip6tables报错解决办法

    问题症状 修改 linux 内核文件 #vi /etc/sysctl.conf后执行sysctl  -P 报错 error: "net.bridge.bridge-nf-call-ip6ta ...

  4. 自定义orderBy字母函数

    orderedUsers: function () { var arr = this.users; for (var i = 0; i < arr.length - 1; i++) { for ...

  5. javascript错误处理(转)

    1.onerror事件处理函数onerror事件处理函数是第一个用来协助javascript处理错误的机制.页面上出现异常时,error事件便在window对象上触发.例如: <html> ...

  6. ES6学习笔记(五)—— 编程风格

    1. 块级作用域 let 取代 var —— let 只在声明的代码块内有效,而且不存在变量提升的效用 const 取代 let —— const 比较符合函数式编程的思想,运算不改变值,只是新建值: ...

  7. 使用Word2010发布博客文章

    发布博客可以直接在web页面上面编辑,也可以使用客户端编辑,其中客户端支持windows live writer以及word本身的发布博客功能.个人试用后倾向于使用word发布博客文章. 下面的内容转 ...

  8. ShadowBroker公开的SMB远程命令执行漏洞修复

    有人不知道如何获得MS对应的补丁KB编号,可以看这篇文章了~ 漏洞编号为ms17-010,如何查看对应MS号的补丁已经安装: 下载微软官方的补丁信息列表(Microsoft Security Bull ...

  9. aiohttp/asyncio 小例子和解释

    #!/usr/bin/env python # encoding: utf-8 import aiohttp import asyncio import time # 通过async def定义的函数 ...

  10. Oracle基础 12 对象 objects 同义词/序列/试图/索引

    --创建同义词create public synonym employees for hr.employees;  --公共同义词需要 create public synonym 权限 表的所有用户授 ...