Coder Social home page Coder Social logo

idevz / vanilla Goto Github PK

View Code? Open in Web Editor NEW
1.0K 134.0 218.0 1.86 MB

An OpenResty Lua MVC Web Framework

Home Page: http://idevz.github.io/vanilla/

License: MIT License

Lua 35.32% Makefile 0.22% Shell 1.92% Perl 62.37% Dockerfile 0.17%
vanilla vanilla-dev vanilla-openresty openresty mvc lua luajit lua-mvc

vanilla's Introduction

Vanilla / (香草中文文档) / OSC Git

https://travis-ci.org/idevz/vanilla.svg?branch=master Join the chat at https://gitter.im/idevz/vanilla

Vanilla is An OpenResty Lua MVC Web Framework.

Vanilla

MailList

Features

  • Provide many good components such as bootstrap, router, controllers, models, views.
  • Powerful plugin system.
  • Multi applications deployment.
  • Multi version of framework coexistence, easier framwork upgrade.
  • Auto complete the Nginx configration.
  • A convenient way to manage Services.
  • You only need to focus your business logic.

Installation

Vanilla-V0.1.0-rc4.1 Or the older Vanillas Installation to see: README-V0.1.0-rc4.1.md
$ ./setup-framework -v $VANILLA_PROJ_ROOT -o $OPENRESTY_ROOT        #see ./setup-framework -h for more details

Quick Start

Setup your Own Application

$ ./setup-vanilla-demoapp  [-a $VANILLA_APP_ROOT -u $VANILLA_APP_USER -g $VANILLA_APP_GROUP -e $VANILLA_RUNNING_ENV]    #see ./setup-vanilla-demoapp -h for more details

Start the server

$ ./$VANILLA_APP_ROOT/va-appname-service start

More Information

License

MIT

Community

QQ Groups&&WeChat public no.

  • Openresty/Vanilla Dev:205773855 (Vanilla panel discussion related topics)
  • Openresty:34782325(Discuss OpenResty and all kinds of advanced technology)
  • WeChat public no. of Vanilla Dev:Vanilla-OpenResty(Vanilla related information, document push)

QQ

vanilla's People

Contributors

gitter-badger avatar hongliang5316 avatar idevz avatar lhmwzy avatar shoother avatar spacewander avatar zyxtomcat avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

vanilla's Issues

多项目 路由缓存bug重现

多项目 路由缓存bug重现

发现vanilla的restful路由存在bug。下面是配置和重现步骤。

注意:web1和web2的的配置 只有 config目录下面 restful.lua 和 controller 下面的 index.lua 不同。其他都一样。下面是配置。

web2 的 restful.lua 比 web1的 restful.lua 多了 匹配详细内容的条件

{pattern = '/:category/:id\\.html', controller = 'index', action = 'detail'}

环境如下

系统:centos6.5 64位
vanilla 版本 :V0.1.0-rc6.1
项目1: /home/webserver/web1 绑定域名 www.web1.com
项目2:/home/webserver/web2 绑定域名 www.web2.com

下面开始配置:

web1 配置

一、bootstrap 配置

web1\application\bootstrap.lua设置如下

function Bootstrap:initRoute()
    local router = self.dispatcher:getRouter()
    local restful_route = restful:new(self.dispatcher:getRequest())
    router:addRoute(restful_route, true)
end

二、restful.lua 配置

启用 restful路由,然后修改 web1\config\restful.lua 如下:

local restful = {
    v={}
}

restful.v.GET = {
    {pattern = '/', controller = 'index', action = 'index'},
    {pattern = '/:category', controller = 'index', action = 'list'}
}

return restful

三、controllers 配置

修改 默认 index.lua 为如下代码


local IndexController = {}

function IndexController:index()
    ngx.say('this is web1 index')
    return ''
end

function IndexController:list()
    ngx.say('this is web1 list')
    return ''
end


return IndexController

web2 配置

一、bootstrap 配置

web2\application\bootstrap.lua设置如下

function Bootstrap:initRoute()
    local router = self.dispatcher:getRouter()
    local restful_route = restful:new(self.dispatcher:getRequest())
    router:addRoute(restful_route, true)
end

二、restful.lua 配置

启用 restful路由,然后修改 web2\config\restful.lua 如下:

local restful = {
    v={}
}

restful.v.GET = {
    {pattern = '/', controller = 'index', action = 'index'},
    {pattern = '/:category', controller = 'index', action = 'list'},
    {pattern = '/:category/:id\\.html', controller = 'index', action = 'detail'}
}

return restful

三、controllers 配置

修改 默认 index.lua 为如下代码


local IndexController = {}

function IndexController:index()
    ngx.say('this is web2 index')
    return ''
end

function IndexController:list()
    ngx.say('this is web2 list')
    return ''
end

function IndexController:detail()
    ngx.say('this is web2 detail')
    return ''
end

return IndexController

开启重现bug:

切换到 web1 项目 /home/webserver/web1,然后 启动项目 ./va-web1-service start

注意是 项目1 启动

然后访问web1:

www.web1.com/ ,没问题
www.web1.com/list ,没问题

然后 访问web2

www.web2.com/ ,没问题
www.web2.com/list ,没问题

www.web2.com/list/123.html 报错了 提示路由不匹配 1Routes All Didn't Match. Errs Like:


注意是 项目2 启动
切换到项目2 /home/webserver/web2。在启动 ./va-web2-service start

然后访问web1:

www.web1.com/ ,没问题
www.web1.com/list ,没问题

然后 访问web2

www.web2.com/ ,没问题
www.web2.com/list ,没问题
www.web2.com/list/123.html 没问题


猜想。bug 大概是因为 路由缓存引起的,当项目1和项目2的 restful 规则一样时候,哪个项目启动都没问题 。当 restful 规则 不一样的时候。哪个项目启动。就按那个项目 restful 规则 解析 所有项目。 所以 除 启动的那个项目没问题。其他项 目 访问 路由 都会 提示 :提示路由不匹配 1Routes All Didn't Match. Errs Like:

Docker start failed

vanilla start vdemo

显示出错信息:

ERROR: Cannot initialize launcher: /usr/local/share/lua/5.1/vanilla/v/libs/utils.lua:54: attempt to index local 'f' (a nil value)

Vanilla Users / Vanilla合作公司

使用Vanilla的公司,可以把相关信息追加到评论中

格式如下

  • 公司名称
  • 官方网站
  • 部署规模(可选)
    此外,可以加我的微信 zhoujingk_49(请注明姓名_公司),我会邀请各位进入Vanilla合作公司 微信群。

便于

  • 有重大的bugfix或者优化改进,及时通知到各位
  • 讨论、确定Vanilla的新需求和发展方向
  • 经验交流

启用waf功能报错

文件:vanilla/vanilla/sys/waf/acc.lua

local utils = require'vanilla.v.libs.utils'

local app_waf_conf = utils.lpcall(function() return require('config.waf') end)

应该改成

local utils = LoadV('vanilla.v.libs.utils')

local app_waf_conf = utils.lpcall(function() return require('config.waf') end)

否则启动waf功能会提示模块找不到

关于 simple 和 restful 的路由选择

为什么在 router.lua 里指定的是 simple 路由
然后在 app 的 bootstrap 里又换成 restful ?

我意思是确定一种不可以吗?
现在我的项目偶尔会“找不到路由”的错误,我追了一下代码发现是 simple 路由引起的,按理说都应该是 restful 才对吧。能不能统一一下??都改成 restful ? @周晶

vanilla关于lua_code_cache使用

vanilla在生产环境下开启lua_code_cache后,第一次请求接口输出正常,再次刷新接口后参数就捕获不到了

./configure error

When I am running the ./configure error .... i am getting output

Didn't set luajit or lua bin. Or did't exists:/usr/local/openresty/luajit/bin/luajit* at ./configure line 131.

I have installed libluabind and luarocks lua5.1 ... but still am getting this error ...

Any help ?

vanilla开发技巧系列------如何转到非默认视图

在Controller中,默认是转到views/控制器名称/方法.html,具体写法如下:

function IndexController:index()
local view = self:getView()
local p = {}
p['vanilla'] = 'Welcome To Vanilla...'
p['zhoujing'] = 'Power by Openresty'
view:assign(p)
return view:display()
end

然而有时我们可能会有转到非默认的页面,比如上面的方法想转到/test/help.html,写法如下:

function IndexController:index()
local view = self:getView()
local p = {}
p['vanilla'] = 'Welcome To Vanilla...'
p['zhoujing'] = 'Power by Openresty'
return view:render("test/help.html", p) -- PS:参数p可以省略
end

关于开发模式下的log写入。

【前提条件】
1.依照github上的readme方式安装vanilla。
2.用非root用户启动vanilla。
3.使用的是development开发模式,端口 7200。

【再现步骤】
1.vanilla start [--trace]
2.tail -f ./logs/development-access.log
3.http://www.openresty.com.cn:7200/index.php
4.http://www.openresty.com.cn:7200/test_waf.php
5.vanilla stop [--trace]

【期待结果】
启动服务后,tail -f development-access.log,伴随每次http请求
实时的输出到访问日志文件里。便于调试监控。

【实际结果】

access log的实时访问数据,只有在vanilla stop [--trace]
之后,才写入到development-access.log。

(PS:某些情况下,会直接抛出写文件异常,error.log,另外一个问题,
忘记截取log了。)

error: attempt to set ngx.status after sending out response headers

I need call B controller method "test" from A controller, so I use "ngx.location.capture" in A controller method.

function AController:index()
    local res = ngx.location.capture("/B/test")
    return res.body
end
function BController:test()
    return ""
end

I access url "http://host/A" but got "attempt to set ngx.status after sending out response headers" error in "logs/production-error.log", how to fix?

Version: rc4 release.

默认application接收到请求是怎么找到view和controller的?

接收到请求:http://127.0.0.1:9110/
1:根据配置跳转
/vanilla/test/tmp/development-nginx.conf:
location / {
content_by_lua_file ./pub/index.lua;
}
2:读取application配置并初始化bootstrap及dispatcher
/vanilla/test/pub/index.lua:
local config = require('config.application') //保存controllers和view的路径
local app = require('vanilla.v.application'):new(config)
3:启动
/vanilla/test/pub/index.lua:
app:bootstrap():run()
3.1:执行boostrap(),执行实例中的boot_list()
3.2:执行dispatcher(),执行plugin,初始化controller,view后返回

查根据返回的页面是返回的view和controllers数据集合,但这两个路径在源码中是怎么找到的呢?
/vanilla/test/application/views/index/index.html
/vanilla/test/application/controllers/index.lua

vanilla开发遇到的问题系列------页面无法正常显示

受影响的版本:v0.1.0-rc3

在“你的应用目录/applications/plugins/admin.lua”文件中,将以下部分注释掉,否则你的页面死活可能显示不正常。

routerStartup方法里的:
--print_r('

')
--if request.method == 'GET' then
-- print_r('-----------' .. sprint_r(request.headers) .. '----------')
--else
-- print_r(request.headers)
--end

PS:作者在下版本应该会去掉!

关于vanilla执行顺序

openresty 的 执行顺序:
set_by_lua
rewrite_by_lua
access_by_lua
content_by_lua
header_filter_by_lua
body_filter_by_lua
log_by_lua

对应vanilla框架 :
application(应用代码主体目录)
│ ├── nginx(*Openresty所封装Nginx请求处理各Phase)

在application 下 的nginx文件 该如何对应实现上述 流程呢?

rc5 安装后

/usr/bin/env: luajit: No such file or directory
需要自己设置吗?

最新版 vanilla页面缓存 key 设置不合理。

git clone vanilla 最新版本安装。然后创建新项目。切换到 安装 框架的 路径 /opt/vanilla/framework/init.lua

编辑 init.lua 文件:

大概在 195行,找到 页面 设置缓存的唯一 key 。

Registry['APP_PAGE_CACHE_KEY'] = ngx.encode_args(clean_args(Registry['REQ_ARGS_ARR']))

可以看出 由 参数组成。但是当 页面没任何参数的时候 。APP_PAGE_CACHE_KEY 打印看到为 “”,空字符串 ,这时候所有不带参数的页面 都会命中 这个空字符串作为的key的 同一缓存。

于是改成这样


Registry['APP_PAGE_CACHE_KEY'] = Registry['APP_NAME']..Registry['REQ_URI_PATH']..'?'..ngx.encode_args(clean_args(Registry['REQ_ARGS_ARR']))

说明:增加缓存匹配唯一APP_PAGE_CACHE_KEY = APP_NAME(项目名称) + ngx.var.uri(当前uri不带参数) + REQ_ARGS_ARR(参数)

这样每个页面的 缓存 APP_PAGE_CACHE_KEY 就不一样了。不管带不带参数。

vanilla的restful路由增加对 类似 /web/lua-intro.html 有 - 的url 匹配

当前restful的配置文件定义

restful.v.GET = {
    {pattern = '/', controller = 'index', action = 'index'},
    {pattern = '/:category', controller = 'index', action = 'list'},
    {pattern = '/:category/:id\\.html', controller = 'index', action = 'detail'}
}

现在定义restyful的url是不能包含-的,如 /web/lua-intro.html ,所以需要修改

vanilla-rc6\framework\0_1_0_rc6\vanilla\v\routes\restful.lua 这个文件中 匹配正则

只需要在正则中增加 - 即可

大概在 22行。找到

local n_p = ngxgsub(pattern, "/:([A-Za-z0-9_-]+)", function(m) tappend(params, m[1]); return "/([A-Za-z0-9_-]+)" end, "io")

生产模式下获取不到restful里面的参数

vanilla 生产模式下 在控制器中 使用 self.params['typedir'] 获取 restful 里面的参数,重启 vanilla 第一次访问页面是可以获取得到 ,第二次访问页面就成了nil

但是在 开发模式下 一直都是能改获取得到的

restful.lua :
restful.v.GET = {
{pattern = '/:typedir/:id', controller = 'index', action = 'detail'},
{pattern = '/:typedir', controller = 'index', action = 'list'},
{pattern = '/', controller = 'index', action = 'index'},
}

vanilla开发技巧系列------输出json到浏览器

local cjson = require "cjson"
function IndexController:index()
-- 解析request参数
local req = self:getRequest()
-- print_r(req:getParams())
local ret = {}
ret.id = req:getParam("id")
ret.name = req:getParam("name")
return cjson.encode(ret)
end

Vanilla-V0.1.0-rc6 loader 找不到档案

使用 release 版的 RC6 (commit id 6da0ac0),建立 demoapp ,会发生 require 失败

env: MAC OS

重现步骤:

  1. release 版的 RC6 (commit id 6da0ac0)解压
  2. ./setup-framework
  3. vanilla-0.1.0.rc6 new /Users/kent/dev/temp/demoapp
  4. chown +x va-demoapp-service
  5. ./va-demoapp-service initconf
  6. sudo ./va-demoapp-service restart
Password:
Restarting va-ok-service: 
Succ. 
  1. curl http://localhost
<html>
<head><title>500 Internal Server Error</title></head>
<body bgcolor="white">
<center><h1>500 Internal Server Error</h1></center>
<hr><center>openresty/1.9.7.4</center>
</body>
</html>

vanilla-error.log

2016/05/14 17:53:10 [error] 1895#0: *12 lua entry thread aborted: runtime error: /Users/kent/dev/temp/demoapp/pub/index.lua:7: module '/usr/local/vanilla/framework/0_1_0_rc6/vanilla.v.libs.utils' not found:
    no field package.preload['/usr/local/vanilla/framework/0_1_0_rc6/vanilla.v.libs.utils']
    no file '//usr/local/vanilla/framework/0_1_0_rc6/vanilla/v/libs/utils.lua'
    no file '//usr/local/vanilla/framework/0_1_0_rc6/vanilla/v/libs/utils/init.lua'
    no file '/usr/local/vanilla/framework//usr/local/vanilla/framework/0_1_0_rc6/vanilla/v/libs/utils.lua'
    no file '/usr/local/vanilla/framework//usr/local/vanilla/framework/0_1_0_rc6/vanilla/v/libs/utils/init.lua'
    no file '/usr/local/openresty/lualib//usr/local/vanilla/framework/0_1_0_rc6/vanilla/v/libs/utils.lua'
    no file '/usr/local/openresty/lualib//usr/local/vanilla/framework/0_1_0_rc6/vanilla/v/libs/utils/init.lua'
    no file './/usr/local/vanilla/framework/0_1_0_rc6/vanilla/v/libs/utils.lua'
    no file '/usr/local/openresty/luajit/share/luajit-2.1.0-beta1//usr/local/vanilla/framework/0_1_0_rc6/vanilla/v/libs/utils.lua'
    no file '/usr/local/share/lua/5.1//usr/local/vanilla/framework/0_1_0_rc6/vanilla/v/libs/utils.lua'
    no file '/usr/local/share/lua/5.1//usr/local/vanilla/framework/0_1_0_rc6/vanilla/v/libs/utils/init.lua'
    no file '/usr/local/openresty/luajit/share/lua/5.1//usr/local/vanilla/framework/0_1_0_rc6/vanilla/v/libs/utils.lua'
    no file '/usr/local/openresty/luajit/share/lua/5.1//usr/local/vanilla/framework/0_1_0_rc6/vanilla/v/libs/utils/init.lua'
    no file '//usr/local/vanilla/framework/0_1_0_rc6/vanilla/v/libs/utils.so'
    no file '/usr/local/vanilla/framework//usr/local/vanilla/framework/0_1_0_rc6/vanilla/v/libs/utils.so'
    no file '/usr/local/openresty/lualib//usr/local/vanilla/framework/0_1_0_rc6/vanilla/v/libs/utils.so'
    no file './/usr/local/vanilla/framework/0_1_0_rc6/vanilla/v/libs/utils.so'
    no file '/usr/local/lib/lua/5.1//usr/local/vanilla/framework/0_1_0_rc6/vanilla/v/libs/utils.so'
    no file '/usr/local/openresty/luajit/lib/lua/5.1//usr/local/vanilla/framework/0_1_0_rc6/vanilla/v/libs/utils.so'
    no file '/usr/local/lib/lua/5.1/loadall.so'
    no file '//usr/local/vanilla/framework/0_1_0_rc6/vanilla.so'
    no file '/usr/local/vanilla/framework//usr/local/vanilla/framework/0_1_0_rc6/vanilla.so'
    no file '/usr/local/openresty/lualib//usr/local/vanilla/framework/0_1_0_rc6/vanilla.so'
    no file './/usr/local/vanilla/framework/0_1_0_rc6/vanilla.so'
    no file '/usr/local/lib/lua/5.1//usr/local/vanilla/framework/0_1_0_rc6/vanilla.so'
    no file '/usr/local/openresty/luajit/lib/lua/5.1//usr/local/vanilla/framework/0_1_0_rc6/vanilla.so'
    no file '/usr/local/lib/lua/5.1/loadall.so'
stack traceback:
coroutine 0:
    [C]: in function 'LoadV'
    /Users/kent/dev/temp/demoapp/pub/index.lua:7: in function </Users/kent/dev/temp/demoapp/pub/index.lua:1>, client: 192.168.1.116, server: demoapp.idevz.com, request: "GET / HTTP/1.1", host: "192.168.1.126"

关于vanilla 插件 的建议

京老大,有个对vanilla插件优化的建议,你看看是否合理:
1、能否为 plugins 里面的插件 绑定到某个 控制器呢? 因为现在定义的插件,在Bootstrap起码启用是全局的,比如权限检查,只对有些控制器使用,有些不使用。

docker 宿主机上编辑项目源码

我的Dockerfile如下

FROM edwin/openresty-alpine

ENV OPENRESTY_VERSION 1.9.7.3
ENV OPENRESTY_PREFIX /opt/openresty
ENV VANILLA_VERSION V0.1.0-rc4.0 
ENV VANILLA_PREFIX /usr/local/vanilla

ENV OPENRESTY_BUILD_DEPS "make gcc  curl perl"

ENV PYTHON_VERSION=2.7.11-r3
ENV PY_PIP_VERSION=7.1.2-r0
ENV SUPERVISOR_VERSION=3.2.0

RUN apk update && apk add -u python=$PYTHON_VERSION py-pip=$PY_PIP_VERSION
RUN pip install supervisor==$SUPERVISOR_VERSION

RUN apk update \
  && apk add --virtual tmp-build-deps $OPENRESTY_BUILD_DEPS  \
  && cd /tmp \
  && curl -sSL https://github.com/idevz/vanilla/archive/${VANILLA_VERSION}.tar.gz | tar -xvz \
  && cd vanilla-0.1.0-rc4.0 \
  && ./configure --prefix=$VANILLA_PREFIX --openresty-path=$OPENRESTY_PREFIX \
  && make install 
ADD ./supervisord.conf /etc/
RUN mkdir -p /var/log/supervisor 
RUN mkdir -p /demo
ADD ./demo /demo
RUN cd /tmp && vanilla new vdemo
EXPOSE 9110
#RUN cd /tmp/vdemo/ && vanilla start
CMD ["/usr/bin/supervisord"]

supervisor.conf 如下

[supervisord]
logfile=/var/log/supervisor/supervisord.log  ; (main log file;default $CWD/supervisord.log)
logfile_maxbytes=50MB       ; (max main logfile bytes b4 rotation;default 50MB)
logfile_backups=10          ; (num of main logfile rotation backups;default 10)
loglevel=info               ; (log level;default info; others: debug,warn,trace)
pidfile=/var/run/supervisord.pid ; (supervisord pidfile;default supervisord.pid)
nodaemon=true              ; (start in foreground if true;default false)
;nodaemon=false              ; (start in foreground if true;default false)
minfds=1024                 ; (min. avail startup file descriptors;default 1024)
minprocs=200                ; (min. avail process descriptors;default 200)
;umask=022                  ; (process file creation umask;default 022)
;user=chrism                 ; (default is current user, required if root)
;identifier=supervisor       ; (supervisord identifier, default is 'supervisor')
;directory=/tmp              ; (default is not to cd during start)
;nocleanup=true              ; (don't clean up tempfiles at start;default false)
;childlogdir=/tmp            ; ('AUTO' child log dir, default $TEMP)
;environment=KEY=value       ; (key value pairs to add to environment)
;strip_ansi=false            ; (strip ansi escape codes in logs; def. false)

[program:vdemo]
command=/bin/sh -c "cd /tmp/vdemo/ && vanilla stop"

[program:demo]
command=/bin/sh -c "cd /demo/ && vanilla start"

[include]
files = supervisord.d/*.ini

在当前目录下 执行 vanilla new demo ,然后想实现修改宿主机demo中的代码,docker run -d -p 9110:9110 edwin/vanilla-openresty-alpine即可显示修改后的效果

how to start my own app after install vanilla?

after I intalled vanilla, i still have no idea about how to start my own app with vanilla, i think i would take me too much time to learn how to start vanilla. so I hope it could support a simple demo or a quick start page to help us to start my own app with vanilla faster...

解决vanilla多项目使用 resty-template模板缓存问题

vanilla创建项目 web1 和 web2 。2个项目。然后分别修改这个项目项目的模板页面

web1项目的模板 首页模板, web1\application\views\index\index.html
改成:

<!DOCTYPE html>
<html>
<body>
<h1>web1</h1>
</body>
</html>

web2项目 的模板 首页模板, web2\application\views\index\index.html
改成:

<!DOCTYPE html>
<html>
<body>
<h1>web2</h1>
</body>
</html>

然后随便一个项目 使用 生产模式 启动,./va-web1-service start 。

然后访问 先后 web1 和 web2 绑定域名 。会发现 页面 都为 web1

这是 resty-template 的缓存问题。现象为 哪个项目先 访问。模板即为那个项目的。

解决办法,修改 /vanilla/framework/0_1_0_rc6/vanilla/v/views/rtpl.lua 文件

在template引用地方关闭模板缓存。增加

template.caching(false)

改成如下:

-- https://github.com/bungle/lua-resty-template
local template = require "resty.template"
template.caching(false)
-- perf
local error = error
local pairs = pairs
local setmetatable = setmetatable
local app_root = Registry['APP_NAME']

vanilla对models部分的处理,是怎么考虑的?

lua对数据的处理,缺乏轮子。很多sql的语句,数据的处理,都需要自己写。如果有封装好的lua数据库框架,数据库编程就会非常方便。
比如现在,没做1个sql操作,就要重写sql连接,sql连接错误处理,分解数据结果等。太麻烦。不知道vanilla对数据models部分是怎么设计的?谢谢

attempt to set ngx.status after sending out response headers

log错误日志中,总会记录这么一条记录attempt to set ngx.status after sending out response headers,使用restful路由,直接在controller控制器只是做个输出操作也会记录这么一条日志,是出在配置上吗

restful模式下 测试报错

使用阿里云 性能测试 工具 测试 vanilla 。发现在使用 restful路由的 url 报500错误。使用简单路由这没有(注明:使用浏览器正常 访问restful 路由url都没这情况),这个情况是否是个bug?

请求头信息:
`概览

Request URL :
http://114.215.93.85/
Request Method : GET
Status Code : 500 Internal Server Error
响应头信息

Server :
openresty/1.9.7.2
Date :
Fri, 25 Mar 2016 07:44:25 GMT
Content-Type :
text/html; charset=UTF-8
Transfer-Encoding :
chunked
Connection :
keep-alive
Power-By :
Vanilla-0.1.0-rc4
请求头信息

Host :
114.215.93.85
Connection :
Keep-Alive
User-Agent :
PTS-HTTP-CLIENT`
响应信息:
"/usr/local/vanilla/vanilla/v/routes/restful.lua:34: bad argument #1 to 'ngxmatch' (string expected, got boolean)"

能否2个路由同时其作用呢

@idevz 京老大,又要麻烦你了,

Bootstrap 路由的 代码:
local router = self.dispatcher:getRouter()
local restful_route = require('vanilla.v.routes.restful'):new(self.dispatcher:getRequest())
router:addRoute(restful_route) --此时协议栈中加上默认的vanilla.v.routes.simple,一共两个路由协议,如果只想使用一个路由协议,可以给addRoute传入第二个参数true

vanilla 使用restful路由后,router:addRoute(restful_route) ,没有加true,但是 只有简单路由生效,
必须要加上 true,变成 router:addRoute(restful_route,true)
restful路由才生效
这2个路由只能有一个起作用 ,能否同时生效呢?
您的注释上写上的: 2个是能起作用的。这个是否是一个bug呢?

English Docs?

Is there an English version of the docs available?

lua_code_cache in conf invalid

I switch lua_code_cache to off in nginx_conf/dev_vhost/xxx.conf, then "restart dev". But no change when I refresh the page in browser if I modify code in "application/controllers/index.lua". I means the cache is always on!

Version: rc6 release.

The openresty app server

Hi, Zhoujing. The correct name spell for the app server you mention is supposed to be "openresty" ~

restful.lua

/config/restful.lua 折腾了半天发现不起作用,后来发现application/bootstrap.lua文件中

function Bootstrap:boot_list()
    return {
        -- Bootstrap.initWaf,
        -- Bootstrap.initErrorHandle,
        -- Bootstrap.initRoute,
        -- Bootstrap.initView,
        -- Bootstrap.initPlugin,
    }
end

Bootstrap.initRoute是注释的,取消注释就ok了,这个新手还真不知道怎么搞。能不能搞个文档啥的

default template engine suffer from shared global var problem.

hello, great job by the way. recently i had find out that the version of default template engine is 1.9 which is suffer from a global var problem bungle/lua-resty-template#25. and the template engine is implement in the path 'framework/resty' that can't be update through opm or update Manually in openresty/lua/resty. maybe it is better way to manage the template engine by opm than just simply implement it in the framework?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.