Skip to content

ninjapenguin/phalanx

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

39 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Phalanx Build Status

A micro framework for nginx-lua currently primarily aimed at producing lightweight, high throughput api's

TL;DR;

local app_router = require("phalanx.router"):new()
local route = require("phalanx.route")

app_router:add(
	'book', route:new('^/book/(%w+)', require("myapp.controller.book"))
)

app_router:add(
	'user', route:new('^/user', require("myapp.controller.user"))
)

ngx.say(
	app_router
	:route()
	:send_headers()
	:body()
)

Install

Download one liner:

git clone https://github.com/ninjapenguin/phalanx.git && cd phalanx && luarocks make

Examples

The below is an example of a simple phalanx site setup

nginx.conf

worker_processes 4;

events {
   worker_connections 1024;
}

http {

    lua_package_path "/web/root/sites/phalanx/lua/?.lua;;";

    include       mime.types;
    sendfile on;

    server {
      lua_code_cache off;
      listen 80;
      server_name phalanx.dev;

      root /web/root/sites/phalanx/public;

      access_log /var/log/nginx/access_phalanx.log;
      error_log /var/log/nginx/error_phalanx.log debug;

      location / {
        try_files $uri @framework;
      }

      location @framework {
        content_by_lua_file '/web/root/sites/phalanx/lua/index.lua';
      }
    }
}

index.lua

local app_router = require("phalanx.router"):new()
local route = require("phalanx.route")

app_router:add(
    'welcome', route:new('^/', require("controller.welcome"))
)

ngx.say(
    app_router
    :route()
    :send_headers()
    :body()
)

controller/welcome.lua

local page = require("phalanx.controller"):extends()
function page:get()
    self.response:body("Hello World")
end

return page

Files

├── lua
│   ├── controller
│   │   └── welcome.lua
│   └── index.lua
└── public
    └── test.html

Dependencies

The below rocks are dependencies (these will be handled for you when installing via luarocks)

[30log] (https://github.com/Yonaba/30log)

luarocks install --server=http://rocks.moonscript.org/manifests/Yonaba 30log

[Penlight] (http://stevedonovan.github.io/Penlight/api/index.html)

luarocks install --server=http://rocks.moonscript.org moonrocks

About

Lua-Nginx micro framework

Resources

Stars

Watchers

Forks

Packages

No packages published