2022-11-04 09:52:27 +00:00
|
|
|
when (NimMajor, NimMinor) < (1, 4):
|
|
|
|
{.push raises: [Defect].}
|
|
|
|
else:
|
|
|
|
{.push raises: [].}
|
2022-06-28 10:22:59 +00:00
|
|
|
|
|
|
|
import
|
|
|
|
stew/shims/net,
|
|
|
|
chronicles,
|
|
|
|
presto
|
|
|
|
import
|
2023-04-05 09:58:59 +00:00
|
|
|
../../waku/v2/waku_node,
|
2022-10-18 17:35:26 +00:00
|
|
|
../../waku/v2/node/rest/server,
|
2023-02-13 14:22:24 +00:00
|
|
|
../../waku/v2/node/rest/debug/handlers as debug_api,
|
|
|
|
../../waku/v2/node/rest/relay/handlers as relay_api,
|
|
|
|
../../waku/v2/node/rest/relay/topic_cache,
|
2022-10-18 17:35:26 +00:00
|
|
|
./config
|
2022-06-28 10:22:59 +00:00
|
|
|
|
|
|
|
|
|
|
|
logScope:
|
2022-11-04 08:40:13 +00:00
|
|
|
topics = "wakunode rest"
|
2022-06-28 10:22:59 +00:00
|
|
|
|
|
|
|
|
2023-02-13 14:22:24 +00:00
|
|
|
proc startRestServer*(node: WakuNode, address: ValidIpAddress, port: Port, conf: WakuNodeConf) =
|
2022-06-28 10:22:59 +00:00
|
|
|
let serverResult = newRestHttpServer(address, port)
|
|
|
|
if serverResult.isErr():
|
|
|
|
notice "REST HTTP server could not be started", address = $address&":" & $port, reason = serverResult.error()
|
|
|
|
return
|
2023-02-13 14:22:24 +00:00
|
|
|
|
2022-06-28 10:22:59 +00:00
|
|
|
let server = serverResult.get()
|
2023-02-13 14:22:24 +00:00
|
|
|
|
2022-06-28 10:22:59 +00:00
|
|
|
## 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 & "/"
|