tobychui / zoraxy

A general purpose HTTP reverse proxy and forwarding tool. Now written in Go!
https://zoraxy.aroz.org
GNU Affero General Public License v3.0
2.96k stars 182 forks source link

[ENHANCEMENTS] Lua scripts #367

Open deathbybandaid opened 9 hours ago

deathbybandaid commented 9 hours ago

Is your feature request related to a problem? Please describe. N/A

Describe the solution you'd like I would like to be able to serve lua script type files. This would be in place of loading a backend server.

Describe alternatives you've considered Run haproxy alongside zoraxy to do the same thing. Just would be nice to do it all in one place.

Additional context I am currently using haproxy addon on pfsense and looking to migrate to zoraxy.

Here's some examples I use on haproxy:

robots This script sends the robots.txt file to not kindly tell google not to scrape the site.

robots = function(applet) 
local response = "User-agent: *\nDisallow: /"
applet:add_header("Content-Length", string.len(response)) 
applet:add_header("Content-Type", "text/plain") 
applet:set_status(200) 
applet:start_response() 
applet:send(response) 
end 

core.register_service("robots", "http", robots)

gandalf This serves a custom 403 page that access via the asked address is forbidden.

gandalf = function(applet) 
local response = "Access is strictly forbidden at this address!"
applet:add_header("Content-Length", string.len(response)) 
applet:add_header("Content-Type", "text/plain") 
applet:set_status(200) 
applet:start_response() 
applet:send(response) 
end 

core.register_service("gandalf", "http", gandalf)

workinprogress This is a custom page to placeholder something that isn't ready yet.

workinprogress = function(applet) 
local response = "This Page is Under Construction!"
applet:add_header("Content-Length", string.len(response)) 
applet:add_header("Content-Type", "text/plain") 
applet:set_status(200) 
applet:start_response() 
applet:send(response) 
end 

core.register_service("workinprogress", "http", workinprogress)
tobychui commented 4 hours ago

@deathbybandaid Thanks for the suggestion.

I think a user script-able interface might be able to attract some more devs into this project, but considered that the complexity of including a Lua interpreter is pretty much similar to a ECMAscript (JavaScript) like interpreter but with a much larger user base, if a scripting interface is provided, it is highly unlikely that it will use Lua.

圖片

Though, I am open for further discussion if anyone want to provide more use-cases and ideas.