feat: initial commit

This commit is contained in:
Eugene Prodan
2021-06-06 20:26:13 +03:00
commit 65c93fa871
4 changed files with 51 additions and 0 deletions

17
docker-compose.yml Normal file
View File

@ -0,0 +1,17 @@
version: "3.9"
services:
haproxy:
image: "haproxy:latest"
ports:
- 80:80
volumes:
- ./haproxy.cfg:/usr/local/etc/haproxy/haproxy.cfg
- ./scripts/:/usr/local/etc/haproxy/scripts/
nginx:
image: "nginx:latest"
redis:
image: "redis:latest"
ports:
- 6379:6379

19
haproxy.cfg Normal file
View File

@ -0,0 +1,19 @@
global
daemon
maxconn 256
log stdout format raw local0 debug
lua-load /usr/local/etc/haproxy/scripts/register.lua
defaults
mode http
timeout connect 5000ms
timeout client 50000ms
timeout server 50000ms
frontend http-in
bind *:80
default_backend servers
http-request use-service lua.hello-world if { path /hello_world }
backend servers
server server1 nginx:80 maxconn 32

10
scripts/guard.lua Normal file
View File

@ -0,0 +1,10 @@
guard = {}
function guard.hello_world(applet)
applet:set_status(200)
local response = string.format([[<html><body>Hello World!</body></html>]], message);
applet:add_header("content-type", "text/html");
applet:add_header("content-length", string.len(response))
applet:start_response()
applet:send(response)
end

5
scripts/register.lua Normal file
View File

@ -0,0 +1,5 @@
package.path = package.path .. "./?.lua;/usr/local/etc/haproxy/scripts/?.lua"
require("guard")
core.register_service("hello-world", "http", guard.hello_world);