summaryrefslogtreecommitdiffstatshomepage
path: root/plugins/webserver/init.lua
blob: 3d68b01e6d5b6166b453dcfa5842983e385e4ba8 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
local exports = {}
exports.name = "webserver"
exports.version = "1.0.0"
exports.description = "A simple web server"
exports.license = "MIT"
exports.author = { name = "Miodrag Milanovic" }

local ws = exports

local app = require('weblit/app')

function ws.startplugin()
	app.bind({
		host = "0.0.0.0",
		port = 8080
	})

	app.use(require('weblit/logger'))
	app.use(require('weblit/auto-headers'))
	app.use(require('weblit/etag-cache'))

	app.route({
		method = "GET",
		path = "/",
	}, function (req, res, go)
		res.code = 200
		res.headers["Content-Type"] = "text/html"
		res.body = "<h1>Hello!</h1>\n"
	end)

	app.start()
end

return exports