EvandroLG / pegasus.lua

:rocket: Pegasus.lua is an http server to work with web applications written in Lua language.
http://evandrolg.github.io/pegasus.lua/
MIT License
418 stars 36 forks source link

feat(router): add a router plugin #131

Closed Tieske closed 6 months ago

Tieske commented 1 year ago

This builds on top of #130

Adds a router plugin.

wmealing commented 9 months ago

I got tricked for a while, as I had forgotten that the string paths were regular expressions. This post is left for other users who may wonder why pegas is not serving matching the expected path.

Any of the "magic characters"

( ) . % + - * ? [ ^ $

Need to be escaped with %, for example the route "/catch-fish"

local routes = {

   ["/catch%-fish"] = {
      GET = function(req, resp)
         resp:statusCode(200)
         resp:addHeader("Content-Type","text/html")
         resp:write("catch")
      end,
   },

I do not consider this a bug, its likely a bug in my comprehension.

Tieske commented 7 months ago

@wmealing I think that's actually a bug, we should (for simplicity sake) escape the path before matching. Such that a path "/my-cool-path/{parameter}" can be used without manually escaping the "-" characters.

Other things:

Any input appreciated.