The httpd module implements a basic HTTP web server.
The built-in web server is coupled with the Lua system so the full programming ability of Lua is available for serving web pages.
In addition to the applications own web pages, there is a secondary server root directory at /lib/htdocs. This is provided by the SDK and contains pages for remote system configuration, update and debug. The service homepage of the device is reachable at http://xx.xx.xx.xx/settings/. The service home page can be password protected or filtered. [TODO: How?]
Apart from serving static files, there are three ways to mix HTML with scripting:
| file.shtml
Server parsed HTML |
Files ending in .shtml are parsed by the server before they are sent to the client.
|
| file.lp
Lua Page |
Files ending in .lp are parsed by the server before they are sent to the client. These files allow server-side includes as above, but they also allow included Lua code.
|
| file.lua
Lua Script |
Files ending in .lua are processed by the Lua interpreter like any other Lua program. They run in the same environment as the underlying event loop. They have access to all global variables. |
Lua commands and expressions inside a Lua Page (.lp) or a Lua Script (.lua) always have access to two predefined variables:
- httpd
- The base instance of the web server running the request.
- cgi
- A table with information about the current request.
Lua scripting can write output to the page using cgi:write(). Do not use print(). The print() command sends its output to stdout as usual, and not to the web page.