2022-06-28 10:22:59 +00:00
|
|
|
{.push raises: [Defect].}
|
|
|
|
|
|
|
|
import
|
|
|
|
stew/shims/net,
|
|
|
|
chronicles,
|
|
|
|
presto
|
|
|
|
import
|
|
|
|
./config,
|
|
|
|
./wakunode2,
|
|
|
|
./rest/server,
|
|
|
|
./rest/debug/debug_api,
|
2022-08-30 13:57:45 +00:00
|
|
|
./rest/relay/[relay_api, topic_cache]
|
2022-06-28 10:22:59 +00:00
|
|
|
|
|
|
|
|
|
|
|
logScope:
|
|
|
|
topics = "wakunode.setup.rest"
|
|
|
|
|
|
|
|
|
|
|
|
proc startRestServer*(node: WakuNode, address: ValidIpAddress, port: Port, conf: WakuNodeConf) =
|
|
|
|
let serverResult = newRestHttpServer(address, port)
|
|
|
|
if serverResult.isErr():
|
|
|
|
notice "REST HTTP server could not be started", address = $address&":" & $port, reason = serverResult.error()
|
|
|
|
return
|
|
|
|
|
|
|
|
let server = serverResult.get()
|
|
|
|
|
|
|
|
## Debug REST API
|
|
|
|
installDebugApiHandlers(server.router, node)
|
|
|
|
|
|
|
|
## Relay REST API
|
|
|
|
if conf.relay:
|
2022-08-30 13:57:45 +00:00
|
|
|
let relayCache = TopicCache.init(capacity=conf.restRelayCacheCapacity)
|
2022-06-28 10:22:59 +00:00
|
|
|
installRelayApiHandlers(server.router, node, relayCache)
|
|
|
|
|
|
|
|
server.start()
|
|
|
|
info "Starting REST HTTP server", url = "http://" & $address & ":" & $port & "/"
|