Add debug switch and API endpoint to stop server when in debug mode.

This commit is contained in:
Jonathan Bernard
2017-04-23 00:18:57 -05:00
parent 06b8914e7b
commit 3e8bbb1676
5 changed files with 14 additions and 2 deletions

View File

@ -1,4 +1,4 @@
import asyncdispatch, bcrypt, jester, json, jwt, osproc, sequtils, tempfile,
import asyncdispatch, bcrypt, jester, json, jwt, os, osproc, sequtils, tempfile,
times, unittest
import ./configuration, ./core, private/util
@ -111,6 +111,7 @@ template requireAuth() =
proc start*(givenCfg: StrawBossConfig): void =
let stopFuture = newFuture[void]()
var workers: seq[Worker] = @[]
routes:
@ -136,4 +137,10 @@ proc start*(givenCfg: StrawBossConfig): void =
buildRef: if @"buildRef" != "": @"buildRef" else: nil,
forceRebuild: false))) # TODO support this with optional query params
runForever()
post "/service/debug/stop":
if not givenCfg.debug: resp(Http404, makeJsonResp(Http404), "application/json")
else:
callSoon(proc(): void = complete(stopFuture))
resp($(%*"shutting down"), "application/json")
waitFor(stopFuture)