Skip to content

A simple url matcher for Nginx-Lua, using Intel's Hyperscan for fast, bulk route matching, and complies with FastRoute syntax. Use this to build your own custom URL router.

License

Notifications You must be signed in to change notification settings

chichicuervo/hs_url_match

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 

Repository files navigation

hs_url_match.lua

A simple url matcher for Nginx-Lua, using Intel's Hyperscan (via luahs) for fast, bulk route matching, and complies with FastRoute syntax.

Use this to build your own custom URL router.

Basic Usage

local hum = require "hs_url_match"
local obj = hum.new()

routes = {
    "/hello/{name}/{today: \\d{1,2}/\\d{1,2}/\\d{2,4}}[/{lang: (?:en|fr|zh)]",
    "/hello/user-{user: \d+}[/]$'
}

regexes = obj.parse(routes, {})
compiled = obj:compile(regexes)

path = "/hello/jason75/11/8/2016"

match = compiled:match(path)

--[[ Output Representation:
match = {
  ["path"] = "/hello/jason75/11/8/2016",
  ["matches"] = {
    [0] = "/hello/jason75/11/8/2016",
    [1] = "jason75",
    [2] = "11/8/2016",
    ["name"] = "jason75",
    ["today"] = "11/8/2016",
  },
  ["id"] = "1",
  ["pattern"] = "^/hello/(?P<name>[^/]+)/(?P<today>\d{1,2}/\d{1,2}/\d{2,4})(?:/\{lang: \(\?:en\|fr\|zh\))?",
}
--]]

About

A simple url matcher for Nginx-Lua, using Intel's Hyperscan for fast, bulk route matching, and complies with FastRoute syntax. Use this to build your own custom URL router.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages