Skip to content

Commit

Permalink
[ts] ability to set port and server host from env
Browse files Browse the repository at this point in the history
  • Loading branch information
mrhyde committed Aug 23, 2024
1 parent b4104e6 commit 201823f
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions source/server.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
/* eslint-disable @typescript-eslint/prefer-nullish-coalescing, @typescript-eslint/strict-boolean-expressions */
import fastify from 'fastify'
import routes from './routes/index.ts'

const DEFAULT_PORT = 3000
// biome-ignore lint/complexity/useLiteralKeys: tsc > biome
const PORT = Number.parseInt(process.env['PORT'] || DEFAULT_PORT.toString(), 10) // eslint-disable-line @typescript-eslint/prefer-nullish-coalescing, @typescript-eslint/strict-boolean-expressions
const DEFAULT_HOST = '127.0.0.1'
const PORT = Number.parseInt(process.env['PORT'] || DEFAULT_PORT.toString(), 10)
const HOST = process.env['HOST'] || DEFAULT_HOST

const server = fastify()

void server.register(routes)

server.listen({ port: PORT, host: '0.0.0.0' }, (err, address) => {
server.listen({ port: PORT, host: HOST }, (err, address) => {
if (err) {
console.error(err)
process.exit(1)
Expand Down

0 comments on commit 201823f

Please sign in to comment.