Skip to content

Commit

Permalink
done
Browse files Browse the repository at this point in the history
  • Loading branch information
ringabout committed Aug 9, 2020
1 parent 3d6b48f commit c5622ed
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/prologue/core/context.nim
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ proc multiMatch*(s: string, replacements: StringTableRef): string =
pos += parseUntil(s, tok, startChar, pos)
result.add tok
if pos < s.len:
assert s[pos-1] == sep, "The char before '{' must be '/'"
assert s[pos - 1] == sep, "The char before '{' must be '/'"
else:
break
inc(pos)
Expand Down
12 changes: 7 additions & 5 deletions src/prologue/core/middlewaresbase.nim
Original file line number Diff line number Diff line change
Expand Up @@ -27,24 +27,26 @@ proc switch*(ctx: Context) {.async.} =
let
handler = findHandler(ctx)
next = handler.handler
var
middlewares = handler.middlewares

ctx.middlewares = middlewares & next
ctx.middlewares = handler.middlewares
ctx.middlewares.add next
ctx.first = false

incSize(ctx)

if ctx.size <= ctx.middlewares.len:
let next = ctx.middlewares[ctx.size - 1]
await next(ctx)
elif ctx.first:
let
handler = findHandler(ctx)
lastHandler = handler.handler
middlewares = handler.middlewares

ctx.localSettings = handler.settings
ctx.middlewares.add middlewares & lastHandler
ctx.middlewares.add handler.middlewares
ctx.middlewares.add lastHandler
ctx.first = false

let next = ctx.middlewares[ctx.size - 1]
await next(ctx)

Expand Down
6 changes: 2 additions & 4 deletions src/prologue/core/nativesettings.nim
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,7 @@ proc newLocalSettings*(data: JsonNode): LocalSettings {.inline.} =

proc newLocalSettings*(configPath: string): LocalSettings {.inline.} =
## Creates a new localSettings.
var data = parseFile(configPath)
result = LocalSettings(data: data)
result = LocalSettings(data: parseFile(configPath))

proc newSettings*(address = "", port = Port(8080), debug = true, reusePort = true,
staticDirs: openArray[string] = ["static"], secretKey = randomString(8),
Expand All @@ -85,7 +84,6 @@ proc newSettings*(configPath: string, address = "", port = Port(8080), debug = t
appName = ""): Settings {.inline.} =
## Creates a new settings.
# make sure reserved keys must appear in settings
var data = parseFile(configPath)
result = Settings(address: address, port: port, debug: debug, reusePort: reusePort,
staticDirs: @staticDirs, appName: appName,
data: data)
data: parseFile(configPath))
2 changes: 1 addition & 1 deletion src/prologue/core/urandom.nim
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@


from strutils import strip
from nimcrypto import randomBytes
from nimcrypto/sysrand import randomBytes

from ../core/types import SecretKey
from ../core/encode import urlsafeBase64Encode
Expand Down
7 changes: 7 additions & 0 deletions src/prologue/middlewares/utils.nim
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@ from ../core/middlewaresbase import switch
import ../core/request


proc testMiddleware*(): HandlerAsync =
result = proc(ctx: Context) {.async.} =
logging.info "debug->begin"
await switch(ctx)
logging.info "debug->end"


proc loggingMiddleware*(appName = "Starlight"): HandlerAsync =
result = proc(ctx: Context) {.async.} =
logging.info "loggingMiddleware->begin"
Expand Down

0 comments on commit c5622ed

Please sign in to comment.