lapis使用
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使用的更多相关文章
- luarocks install with lua5.1 and luajit to install lapis
# in luarocks source directory...git clone https://github.com/archoncap/luarockscd luarocks ./config ...
- lapis 项目添加prometheus 监控集成grafana
操作很简单,主要是进行界面的配置以及prometheus 服务的配置, 可以和https://www.cnblogs.com/rongfengliang/p/10074044.html &&a ...
- lapis 项目添加prometheus 监控
lapis 是基于openresty 扩展的,所以直接将支持prometheus的模块构建进openresty 就可以了 我使用的是nginx-module-vts 模块 环境准备 我已经构建好了 ...
- lapis 1.7.0 更好的openresty 版本兼容以及安全数据库支持
lapis 1.7.0 今年4月2号就发布了,一直没有注意,今天看到changelog就简单的进行了一个 测试(主要是与openresty版本的测试,新变更后边会有) 使用docker-compose ...
- lapis docker 运行说明
1. lapis docker 镜像制作 因为openresty 新版本一个json 库的问题,我们使用的是 openresty:1.11.2.1 基础镜像 FROM openresty/openre ...
- lapis 处理接收到的json 数据
备注: 在restful api 开发过程中,大家一般使用的都是json 格式的数据lapis 在处理json 数据上也是比较方便的 1. 使用的api 说明 local ...
- luarocks yum 安装引起的lapis lua 包查找问题(centos7版本)
备注: 大家在进行lapis 开发的时候有些人比较懒直接使用yum 按照luarocks,之后 使用luarocks 安装lapis 一般来说对于linux 64位的环境都会有些问题(包找 ...
- lapis 集成openresty最新版本cjson 问题的解决
备注: 为了解决安装了lapis.同时又希望使用新版nginx 以及openresty 的特性(stream ...) 1. 解决方法 参考: https://github.com/leaf ...
- lapis cockroachdb 数据访问试用
备注: cockroachdb 的安装可以参考官方文档,以下实例代码使用的是官方的参考例子 1. 数据库配置 // config.lua 参考: local config = require( ...
- lapis 数据库配置
备注: 目前支持 postgresql .mysql (实际使用大家可以尝试用下tidb.CockroachDB) 1. pg数据库配置 // config.lua local config = ...
随机推荐
- IDEA 用maven创建web项目编译时不能发布resources中的文件
1.在pom.xml加入 <build> <resources> <resource> <directory>${basedir}/src/main/j ...
- Nginx support TCP Load balance
1. Install nginx package 2. edit nginx configuration file [root@ip- nginx]# more nginx.conf user ngi ...
- c++虚析构函数的必要性
我们知道,用C++开发的时候,用来做基类的类的析构函数一般都是虚函数. 可是,为什么要这样做呢?下面用一个小例子来说明: #include<iostream> using namespac ...
- 前端面试:css预处理
css预处理定义: 定义了一种新的语言,其基本思想是用一种专门编程语言,为css增加了一些编程的特性,将css作为目标生成文件,然后开发者就只要使用这种语言进行编码工作. 几种预处理语言 sass l ...
- tomcat编码配置
<Connector port="8080" protocol="HTTP/1.1" connectionTimeout="20000" ...
- 数学:乘法逆元-拓展GCD
乘法逆元应用在组合数学取模问题中,这里给出的实现不见得好用 给出拓展GCD算法: 扩展欧几里得算法是指对于两个数a,b 一定能找到x,y(均为整数,但不满足一定是正数) 满足x*a+y*b=gcd(a ...
- SSL步骤
SSL步骤 被认证的服务器 1.创建keystore 2.创建信任证书 3.导出信任证书供客户端使用 客户端 1.创建keystore(如果不存在) 2.导入信任证书
- BZOJ 4206: 最大团
4206: 最大团 Time Limit: 10 Sec Memory Limit: 256 MBSubmit: 91 Solved: 36[Submit][Status][Discuss] De ...
- SHOI 2007 仙人掌图(BZOJ 1023)
1023: [SHOI2008]cactus仙人掌图 Time Limit: 1 Sec Memory Limit: 162 MBSubmit: 2564 Solved: 1062 Descrip ...
- 通过jQuery实现轮播效果
HTML <div class="wrap"> <div id="slide"> <ul class="list&quo ...