diff --git a/short_url.nimble b/short_url.nimble index 77180d9..0826cdd 100644 --- a/short_url.nimble +++ b/short_url.nimble @@ -1,6 +1,6 @@ # Package -version = "1.0.0" +version = "1.0.1" author = "Jonathan Bernard" description = "URL shortener/expander for Probatem at https://pbtm.us" license = "GPL3" @@ -11,7 +11,7 @@ bin = @["short_url"] # Dependencies requires "nim >= 2.2.4" -requires @["cliutils", "mummy", "namespaced_logging >= 2.1.2", "webby"] +requires @["cliutils", "mummy", "namespaced_logging >= 2.1.2", "regex", "webby"] task updateVersion, "Update the version of this package.": exec "update_version interactive src/short_url.nim" diff --git a/src/short_url.nim b/src/short_url.nim index 4509e02..4448ea8 100644 --- a/src/short_url.nim +++ b/src/short_url.nim @@ -1,5 +1,5 @@ -import std/[json, nre, posix, sequtils, strutils] -import cliutils, docopt, mummy, namespaced_logging +import std/[json, posix, sequtils, strutils] +import cliutils, docopt, mummy, namespaced_logging, regex import webby/httpheaders const USAGE = """ @@ -14,7 +14,7 @@ Options: --trace Enable trace-level logging (takes precedence over --debug). """ -const VERSION = "1.0.0" +const VERSION = "1.0.1" const CT_TXT = "text/plain" type @@ -24,7 +24,7 @@ type cfg: CombinedConfig Context = object - mappings: seq[tuple[src:string, regex: Regex, tmpl: string]] + mappings: seq[tuple[src:string, regex: Regex2, tmpl: string]] logger: Logger proc loadConfig(args: Table[string, Value]): ShortUrlsConfig = @@ -40,8 +40,8 @@ proc loadConfig(args: Table[string, Value]): ShortUrlsConfig = result.mappings.add((k, v.getStr)) proc initMappings(m: seq[tuple[src, dst: string]]): - seq[tuple[src: string, regex: Regex, tmpl: string]] = - result = m.mapIt((it.src, re(it.src), it.dst)) + seq[tuple[src: string, regex: Regex2, tmpl: string]] = + result = m.mapIt((it.src, re2(it.src), it.dst)) proc makeHandler(mappings: seq[tuple[src,dst: string]], logSvc: LogService): RequestHandler = let ctx = Context( @@ -56,7 +56,7 @@ proc makeHandler(mappings: seq[tuple[src,dst: string]], logSvc: LogService): Req return for (src, regex, tmpl) in ctx.mappings: - if match(req.uri, regex).isSome: + if req.uri.startsWith(regex): ctx.logger.debug(%*{ "msg": "found match", "matching_pattern": %src,