Add siad connection check

This commit is contained in:
PJ 2020-01-22 21:13:38 +01:00
parent 103a89bc98
commit 98b649702d
1 changed files with 18 additions and 0 deletions

View File

@ -49,6 +49,13 @@ export class Server {
this.app.listen(port, () => { this.app.listen(port, () => {
this.logger.info(`Listening on port ${port}`) this.logger.info(`Listening on port ${port}`)
}) })
this.logger.info("Verifying connection to siad...")
this.verifyConnection().then((version: string | null) => {
if (version) {
this.logger.info(`siad reachable, version ${version}`)
}
})
} }
private configureMiddleware() { private configureMiddleware() {
@ -76,6 +83,17 @@ export class Server {
this.app.post("/linkfile", this.handleLinkfilePOST.bind(this)) this.app.post("/linkfile", this.handleLinkfilePOST.bind(this))
} }
private async verifyConnection(): Promise<string | null> {
try {
const resp = await siad.get('/daemon/version')
return resp.data.version
} catch (err) {
const { message } = err;
this.logger.error(message)
return null
}
}
private handleSialinkGET() { private handleSialinkGET() {
return proxy(`${SIAD_ENDPOINT}/renter/sialink`, { return proxy(`${SIAD_ENDPOINT}/renter/sialink`, {
proxyReqOptDecorator: (opts, _) => { proxyReqOptDecorator: (opts, _) => {