How to serve lua pages / scripts in a simple, painless way?

I have been using the Lua programming language for all types of scripts since some time, and I want to stay with it (is it my sixt language or something else). But I cannot find a solution to make very simple lua web applications that are very frustrating.

I tried WSAPI, Orbit, mongrel2 and try to make a simple and understandable system to serve a very simple LGA CGI, but I failed, it always gets into a system with many dependencies, rather than portable ones, and are interspersed with many files and distributions and subscriptions. .. I even tried to modify nanoki, the same result. Of course, I learned something, but I was at the same time when I started. Lua does not seem to be welcome in the field of web development.

In django or web2py or php, I can make simple applications in three minutes. But I'm blowing up a simple script / functionality with dozens of files. Or should I use a language that I hate moderately (php).

I need something that stays in my way, like web.py or cherrypy or pow for ruby, but in lua.

I compiled haserl, but I don’t know how to use it, since it lacks documentation (a common problem in the lua world, unfortunately). mod_lua / apache, may be fine, but I did not find the page on all the internet using some examples. The same goes for mod_magnet in lighttpd and nginx + lua.

I'm starting to feel upset. I don’t need servers with fast speed on the millionth user website, I need to serve simple dynamic lua content over LAN. I don’t think what to demand from a rocket scientist ...

So what will you do? Is there somewhere a minimal simple web server that supports standard cgi in lua? Something plug and play, and let us and you focus on what the script does, and not how to make simple things absurdly complex in evil ways?

PS: My environments are Linux.

+4
source share
4 answers

Have you heard of Luvit ? This is basically NodeJS in Lua

Luvit official website

Github repo

A simple script would look like this:

local HTTP = require("http") HTTP.create_server("0.0.0.0", 8080, function (req, res) local body = "Hello world\n" res:write_head(200, { ["Content-Type"] = "text/plain", ["Content-Length"] = #body }) res:finish(body) end) print("Server listening at http://localhost:8080/") 

Here is the original message from the creator.

+5
source

I would like to point out the CGI library that I wrote for Lua that describes the exact problems you called - dependencies.

LunarCGI at its core consists of only 3 files (only Lunar * .lua files are required) that support HTML templates (and even simple file loading, although it does not support binary files [yet!]).

Try: https://github.com/beelzebub/lunarcgi

+1
source

Try Civetweb , it is a small, powerful and embeddable web server. It can serve lua pages and even has built-in sqlite support, so you may have a database for your web application. It also supports cgi, as you requested. Binaries are available at SourceForge .

+1
source

If writing code is your main concern, Orbit also comes with Lua Pages , which is similar to php in use (so you have inline code in your html).

0
source

Source: https://habr.com/ru/post/1387080/


All Articles