-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.lua
More file actions
103 lines (78 loc) · 2.07 KB
/
server.lua
File metadata and controls
103 lines (78 loc) · 2.07 KB
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
_G.require = require
-- _G.Logger = require("./core/Logger")
function _G.trace(...)
print(...)
-- return _G.Logger:trace(...)
end
local Fuzzy = require('./libs/fuzzy/Fuzzy')
local Static = require('./libs/fuzzy/middlewares/Static')
local FileSystemRouter = require("./libs/fuzzy/routers/FileSystemRouter")
-- local ftml = FTML:new({
-- directory = "./routes/"
-- })
-- local router = FuzzyFSRouter:new({
-- directory = "./routes/"
-- })
--- TODO
-- make a base extendable router
-- use the base router and extend for fuzzy app.
-- use router and extend more for fs router
-- fs router will accept middlewares, like FTML
-- +PURPOSE[.format].lua
--use sqlite3, thsi is not that important to use pgsql
-- and use libs for like multipart or json idk :33333
-- local app = App:new()
-- app:use(router)
local app = Fuzzy.App:new()
--todo, support path
app:use(--[["/static/", ]]Static:new())
app:use(function(req, res)
-- res:send("hi")
-- print(req.url)
end)
local penis = FileSystemRouter:new({
path = "/",
directory = "./routes"
})
-- penis:get("/bai", function(req, res)
-- print("hiiii: ", req.url)
-- end)
app:mount(penis)
-- app:get("/", function(req, res)
-- res:send("yawn")
-- end)
-- app:get("/t/:id/:NEW", function(req, res)
-- res:send("yawn PARAMS " .. req.params.id .. " " .. req.params.NEW)
-- end)
-- app:get("/a-:bwa", function(req, res)
-- trace(req.params.bwa)
-- if req.params.bwa == "meow" then
-- res:send("hi")
-- end
-- res:pass()
-- end)
-- app:get("/a-:bwa", function(req, res)
-- res:send("passed, bwa")
-- end)
-- app:get("/funny", function(req, res)
-- trace("zzz")
-- res:send("yawn")
-- end)
-- no work cuz escape
app:method("ANY", "(.*)", function(req, res)
res:send("404")
end)
app:start({
port = 8000,
onstart = function(server, ip, port)
print(("running on http://%s:%d"):format(ip, port))
end
})
--- cahnge this to use ARGS (arg 1 is the start;scriptname, arg 0 is the exec)
--to enable debugging, use env DBG=1 in cli
--- TODO
--- fix 404
--- do fsrouter
--- do ftml
---
--- make this work on windows?