An OpenResty Lua MVC Web Framework

Download as .zip Download as .tar.gz View on GitHub

Vanilla / (香草中文文档) / OSC Git Join the chat at Issue Stats Issue Stats

Vanilla is An OpenResty Lua MVC Web Framework.




Vanilla-V0.1.0-rc4.1 Or the older Vanillas Installation to see:

Use ./setup-framework Install Vanilla

./setup-framework is a auto script to make install Vanilla, only need to set OpenResty install path to install Vanilla in a simple way

./setup-framework -h
Usage: ./setup-framework
                 -h   show this help info
                 -v   VANILLA_PROJ_ROOT, vanilla project root, will contain vanilla framework and apps
                 -o   OPENRESTY_ROOT, openresty install path(openresty root)

Options of ./setup-framework:

Here is the Directory Structure:

tree /data/vanilla -L 2
├── framework
│   ├── 0_1_0_rc5
│   └── 0_1_0_rc5.old_2016_04_12_11_04_18 # Repeat the installation will mv the older one to an time backup.

Use make install cmd to install Vanilla

Vanilla support many configuration options, many of those option have default value.

You can use default installation but if your enviroment values different from which vanilla default, please config it with yours. Especially the --openresty-path option. you should make sure it's point to your turely OpenResty install path. You can run command ./configure --help to learn how to use those options.

Below is the installation of a simple example:

./configure --prefix=/usr/local/vanilla --openresty-path=/usr/local/openresty

make install

Vanilla usage

Vanilla-V0.1.0-rc4.1 Or the older Vanillas Installation to see:

Vanilla CMDs

Vanilla-V0.1.0-rc5 always support two cmds, but from rc5, each cmd just like the framework itselvese generate with an version number like vanilla-0.1.0.rc5, and v-console-0.1.0.rc5, this is good for muilt version vanilla coexistence and painless upgrade Vanilla.

Building up an application skeleton

vanilla-0.1.0.rc5 new app_full_path                         #use cmd `vanilla-0.1.0.rc5` to auto create an app skeleton, Attention to give an full path as an param, but not just an APP_NAME
chmod +x app_full_path/va-appname-service                   #add an execute permissions to va-appname-service
app_full_path/va-appname-service initconf [dev]             #init the nginx config for the app, the nginx config file base on the config file in app_full_path/nginx_conf, if you have any personal configration, you should add thire into those config files first, then you can execute the initconf action, param [dev] is an optional one, add this for development environment, default empty for production environment.
app_full_path/va-appname-service start [dev]                #start this inited service, then you can visit it through http://localhost, it also have a [dev] option just like initconf.

These multi process can be simply completed through script ./setup-vanilal-demoapp:

./setup-vanilal-demoapp -h
Usage: ./setup-vanilal-demoapp -h   show this help info
                 -a   VANILLA_APP_ROOT, app absolute path(which path to init app)
                 -u   VANILLA_APP_USER, user to run app
                 -g   VANILLA_APP_GROUP, user group to run app
                 -e   VANILLA_RUNNING_ENV, app running environment

Options of ./setup-vanilal-demoapp

Here is the Directory Structure:

tree /data/vanilla/ -L 1
├── framework                             # vanilla framework path
├── vademo                                # demo app "vademo" path
└── vademo.old_2016_04_12_11_04_26        # Repeat the installation will mv the older one to an time backup.

Application init and service management

We use script /data/vanilla/vademo/va-vademo-service to manage the vademo service

/data/vanilla/vademo/va-vademo-service -h
Usage: ./va-ok-service {start|stop|restart|reload|force-reload|confinit[-f]|configtest} [dev] #dev set up the running environment, none dev for default production envionment.

Tips:* You should run cmd /data/vanilla/vademo/va-vademo-service initconf [dev] first if you new the App didn't use the /data/vanilla/vademo/va-vademo-service script but run cmd vanilla-0.1.0.rc5 new vademo to new an app by hand.*

Directory Structure

 /Users/zj-git/app_name/ tree ./
├── application
│   ├── bootstrap.lua --application boot
│   ├── controllers
│   │   ├── error.lua --application error handling, dealing with corresponding business under this path error
│   │   └── index.lua --vanilla hello world
│   ├── library       --local libs
│   ├── models 
│   │   ├── dao       --data handles for DB, APIs
│   │   │   └── table.lua
│   │   └── service   --encapsulations of DAOs
│   │       └── user.lua
│   ├── nginx         --openresy http phases
│   │   └── init.lua  --init_by_lua demo
│   ├── plugins
│   └── views         --one to one correspondence to controllers
│       ├── error     --error handle view layout
│       │   └── error.html
│       └── index     --index controller views
│           └── index.html
├── config
│   ├── application.lua --app basic configuration such as router,initialization settings...
│   ├── errors.lua    --app error conf
│   ├── nginx.conf    --nginx.conf skeleton
│   ├── nginx.lua     --nginx settings like lua_code_cache.
│   ├── waf-regs      --WAF rules
│   │   ├── args
│   │   ├── cookie
│   │   ├── post
│   │   ├── url
│   │   ├── user-agent
│   │   └── whiteurl
│   └── waf.lua       --app WAF config
├── logs
│   └── hack          --attack logs, keep path can be write
├── pub               --app content_by_lua_file path
    └── index.lua     --entrance file

IndexController Demo

local IndexController = {}

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

return IndexController
Template demo (views/index/index.html)
<!DOCTYPE html>
  <img src="">
  <h1><a href = ''>{{vanilla}}</a></h1><h5>{{zhoujing}}</h5>

Why Vanilla

To answer this question, we just need to see what Openresty has done and Vanilla has done.




QQ Groups&&WeChat public no.