forked from volmar/civic
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathserver.lua
49 lines (46 loc) · 1.52 KB
/
server.lua
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
local weblit = require('weblit')
local user = require "actors/user"
weblit.app
.bind({host = "127.0.0.1", port = 1337})
-- Configure weblit server
.use(weblit.logger)
.use(weblit.autoHeaders)
-- Web Application entrypoint
.route({path = "/"}, function (req, res)
res.body = req.method .. " - Welcome to init \n"
res.code = 200
res.headers["Content-Type"] = "text/html"
end)
.route({path = "/solicitud"}, function (req, res)
res.body = "[]"
-- .. req.query.fulltext .. "\n"
res.code = 200
res.headers["Content-Type"] = "application/json"
end)
.route({path = "/solicitud/:folio"}, function (req, res)
res.body = req.method .. " - Folio: " .. req.params.folio .. "\n"
res.code = 200
res.headers["Content-Type"] = "text/html"
end)
.route({path = "/solicitud/:folio/watch"}, function (req, res)
res.body = '{"message":"success"}'
res.code = 200
res.headers["Content-Type"] = "application/json"
end)
.route({path = "/solicitud/:folio/stopwatch"}, function (req, res)
res.body = '{"message":"success"}'
res.code = 200
res.headers["Content-Type"] = "application/json"
end)
.route({path = "/user"}, function (req, res)
res.body = '{"message":"' .. user(123) .. '"}\n'
res.code = 200
res.headers["Content-Type"] = "application/json"
end)
.route({ path = "/:name"}, function (req, res)
res.body = req.method .. " - " .. req.params.name .. "\n"
res.code = 200
res.headers["Content-Type"] = "text/plain"
end)
-- Start the server
.start()