mirror of
https://github.com/logos-storage/logos-storage-nim.git
synced 2026-01-04 22:43:12 +00:00
Make rest api server optional
This commit is contained in:
parent
34976c3c58
commit
d9f5261b80
@ -184,20 +184,25 @@ proc start*(s: CodexServer) {.async.} =
|
||||
|
||||
await s.bootstrapInteractions()
|
||||
await s.codexNode.start()
|
||||
s.restServer.start()
|
||||
|
||||
if s.restServer != nil:
|
||||
s.restServer.start()
|
||||
|
||||
proc stop*(s: CodexServer) {.async.} =
|
||||
notice "Stopping codex node"
|
||||
|
||||
let res = await noCancel allFinishedFailed[void](
|
||||
var futures =
|
||||
@[
|
||||
s.restServer.stop(),
|
||||
s.codexNode.switch.stop(),
|
||||
s.codexNode.stop(),
|
||||
s.repoStore.stop(),
|
||||
s.maintenance.stop(),
|
||||
]
|
||||
)
|
||||
|
||||
if s.restServer != nil:
|
||||
futures.add(s.restServer.stop())
|
||||
|
||||
let res = await noCancel allFinishedFailed[void](futures)
|
||||
|
||||
if res.failure.len > 0:
|
||||
error "Failed to stop codex node", failures = res.failure.len
|
||||
@ -333,10 +338,13 @@ proc new*(
|
||||
taskPool = taskpool,
|
||||
)
|
||||
|
||||
var restServer: RestServerRef = nil
|
||||
|
||||
if config.apiBindAddress.isSome:
|
||||
restServer = RestServerRef
|
||||
.new(
|
||||
codexNode.initRestApi(config, repoStore, config.apiCorsAllowedOrigin),
|
||||
initTAddress(config.apiBindAddress, config.apiPort),
|
||||
initTAddress(config.apiBindAddress.get(), config.apiPort),
|
||||
bufferSize = (1024 * 64),
|
||||
maxRequestBodySize = int.high,
|
||||
)
|
||||
|
||||
@ -203,8 +203,10 @@ type
|
||||
.}: string
|
||||
|
||||
apiBindAddress* {.
|
||||
desc: "The REST API bind address", defaultValue: "127.0.0.1", name: "api-bindaddr"
|
||||
.}: string
|
||||
desc: "The REST API bind address",
|
||||
defaultValue: "127.0.0.1".some,
|
||||
name: "api-bindaddr"
|
||||
.}: Option[string]
|
||||
|
||||
apiPort* {.
|
||||
desc: "The REST Api port",
|
||||
|
||||
@ -141,6 +141,8 @@ proc createCodex(
|
||||
return err("Failed to create codex: unable to get the private key.")
|
||||
let pk = privateKey.get()
|
||||
|
||||
conf.apiBindAddress = string.none
|
||||
|
||||
let server =
|
||||
try:
|
||||
CodexServer.new(conf, pk)
|
||||
|
||||
@ -51,7 +51,8 @@ proc ethAccount*(node: CodexProcess): Address =
|
||||
|
||||
proc apiUrl*(node: CodexProcess): string =
|
||||
let config = CodexConf.load(cmdLine = node.arguments, quitOnFailure = false)
|
||||
return "http://" & config.apiBindAddress & ":" & $config.apiPort & "/api/codex/v1"
|
||||
return
|
||||
"http://" & config.apiBindAddress.get() & ":" & $config.apiPort & "/api/codex/v1"
|
||||
|
||||
proc client*(node: CodexProcess): CodexClient =
|
||||
if client =? node.client:
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user