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