xrforge-v2/src/middleware/onlyGET.lua

24 lines
501 B
Lua

-- soakbean middleware function
return function(opts)
opts = opts or {exclude={"^/admin"}}
return function(req,res,next)
local pass = false
if req.method == "GET" or req.method == "HEAD" then
pass = true
else
foreach(opts.exclude, function(k,path)
if req.url:match(path) then
pass = true
end
end)
end
if pass then
next()
else
res.status(405)
res.body("not allowed")
res.send(req,res)
end
end
end