Rewrote host environment targets to work out of the box
[project/luci.git] / libs / httpd / host / runluci
1 #!/usr/bin/lua
2 require("luci.httpd")
3 require("luci.httpd.server")
4 require("luci.httpd.handler.file")
5 require("luci.httpd.handler.luci")
6
7 SYSROOT = arg[1]
8 DOCROOT = SYSROOT .. arg[2]
9 PORT = 8080
10
11 collectgarbage("setpause", 150)
12
13 serversocket = luci.httpd.Socket("0.0.0.0", PORT)
14
15 server = luci.httpd.server.Server()
16 vhost = luci.httpd.server.VHost()
17
18 server:set_default_vhost(vhost)
19
20 if pcall(require, "uci") and pcall(require, "luci.model.uci") then
21 luci.model.uci.confdir_default = SYSROOT .. luci.model.uci.confdir_default
22 luci.model.uci.savedir_state = SYSROOT .. luci.model.uci.savedir_state
23 luci.model.uci.set_confdir(luci.model.uci.confdir_default)
24 end
25
26
27 filehandler = luci.httpd.handler.file.Simple(DOCROOT)
28 vhost:set_default_handler(filehandler)
29
30 lucihandler = luci.httpd.handler.luci.Luci()
31 vhost:set_handler("/luci", lucihandler)
32
33 io.stderr:write("Starting LuCI HTTPD on port " .. PORT .. "...\n")
34 io.stderr:write("Point your browser to http://localhost:" .. PORT .. "/luci\n")
35
36 --daemon = luci.httpd.Daemon()
37 --daemon.debug = true
38 luci.httpd.register(serversocket, server:create_daemon_handlers())
39 luci.httpd.run()