xrforge-v2/src/middleware/onlyGET.lua

25 lines
501 B
Lua
Raw Normal View History

-- soakbean middleware function
return function(opts)
opts = opts or {exclude={"^/admin"}}
return function(req,res,next)
local pass = false
2026-08-24 13:29:35 +02:00
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