Skip to content

Commit

Permalink
Merge pull request #24 from ipfs/feat/use-constants-file
Browse files Browse the repository at this point in the history
  • Loading branch information
SgtPooki authored Oct 23, 2023
2 parents 118f993 + b8549b8 commit 1675996
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
3 changes: 3 additions & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export const PORT = Number(process.env.PORT ?? 8080)

export const HOST = process.env.HOST ?? '0.0.0.0'
3 changes: 2 additions & 1 deletion src/healthcheck.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#!/usr/bin/env node
import { HOST, PORT } from './constants.js'
/**
* This healthcheck script is used to check if the server is running and healthy.
*/
const rootReq = await fetch(`http://localhost:${process.env.PORT ?? 8080}`, { method: 'GET' })
const rootReq = await fetch(`http://${HOST}:${PORT}`, { method: 'GET' })
const status = rootReq.status
// eslint-disable-next-line no-console
console.log(`Healthcheck status: ${status}`)
Expand Down
5 changes: 1 addition & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import debug from 'debug'
import express from 'express'
import promBundle from 'express-prom-bundle'
import session from 'express-session'
import { HOST, PORT } from './constants.js'
import { HeliaServer, type IRouteEntry } from './heliaServer.js'

const logger = debug('helia-server')
Expand All @@ -10,10 +11,6 @@ const promMetricsMiddleware = promBundle({ includeMethod: true })
const heliaServer = new HeliaServer(logger)
await heliaServer.isReady

// Constants
const PORT = (process?.env?.PORT ?? 8080) as number
const HOST = process?.env?.HOST ?? '0.0.0.0'

// Add the prometheus middleware
const app = express()
app.use(promMetricsMiddleware)
Expand Down

0 comments on commit 1675996

Please sign in to comment.