From 60df7917babf851c277d2174389502a1de9fce54 Mon Sep 17 00:00:00 2001 From: Ivan Folgueira Bande Date: Wed, 24 Apr 2024 15:12:34 +0200 Subject: [PATCH] wakunode2 and builder: only start rest server when enabled from conf --- apps/wakunode2/wakunode2.nim | 11 +++++------ waku/waku_api/rest/builder.nim | 6 ++++++ 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/apps/wakunode2/wakunode2.nim b/apps/wakunode2/wakunode2.nim index 39dc8d7b57..f14a1f97f5 100644 --- a/apps/wakunode2/wakunode2.nim +++ b/apps/wakunode2/wakunode2.nim @@ -146,12 +146,11 @@ when isMainModule: error "Starting app failed", error = error quit(QuitFailure) - if conf.rest: - rest_server_builder.startRestServerProtocolSupport( - restServer, wakunode2.node, wakunode2.wakuDiscv5, conf - ).isOkOr: - error "Starting protocols support REST server failed.", error = $error - quit(QuitFailure) + rest_server_builder.startRestServerProtocolSupport( + restServer, wakunode2.node, wakunode2.wakuDiscv5, conf + ).isOkOr: + error "Starting protocols support REST server failed.", error = $error + quit(QuitFailure) wakunode2.startMetricsServerAndLogging().isOkOr: error "Starting monitoring and external interfaces failed", error = error diff --git a/waku/waku_api/rest/builder.nim b/waku/waku_api/rest/builder.nim index 0bfc65e32f..e5b4893341 100644 --- a/waku/waku_api/rest/builder.nim +++ b/waku/waku_api/rest/builder.nim @@ -35,6 +35,9 @@ restServerNotInstalledTab = newTable[string, string]() proc startRestServerEsentials*( nodeHealthMonitor: WakuNodeHealthMonitor, conf: WakuNodeConf ): Result[WakuRestServerRef, string] = + if not conf.rest: + return + let requestErrorHandler: RestRequestErrorHandler = proc( error: RestRequestError, request: HttpRequestRef ): Future[HttpResponseRef] {.async: (raises: [CancelledError]).} = @@ -112,6 +115,9 @@ proc startRestServerProtocolSupport*( wakuDiscv5: Option[WakuDiscoveryV5], conf: WakuNodeConf, ): Result[void, string] = + if not conf.rest: + return + var router = restServer.router ## Admin REST API if conf.restAdmin: