Skip to content

Commit

Permalink
Add ternary operator to check if CORS_ORIGIN is string and remove con…
Browse files Browse the repository at this point in the history
…sole.log
  • Loading branch information
FrankApiyo committed May 11, 2023
1 parent 0013eaf commit 8bd36bb
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ async function build() {
}
})
.catch((error) => {
console.log(error)
req.log.error(err)
done(error.detail);
});
} else if ("/health-check" == req.url) {
Expand Down Expand Up @@ -72,7 +72,7 @@ async function build() {
})

// CORS
fastify.register(require('@fastify/cors'), { origin: JSON.parse(process.env.CORS_ORIGINS) })
fastify.register(require('@fastify/cors'), { origin: typeof process.env.CORS_ORIGIN === 'string' ? JSON.parse(process.env.CORS_ORIGINS) : process.env.CORS_ORIGINS })

// OPTIONAL RATE LIMITER
if ("RATE_MAX" in process.env) {
Expand Down Expand Up @@ -130,9 +130,9 @@ build()
.then(fastify => // LAUNCH SERVER
fastify.listen({ port: process.env.SERVER_PORT || 3000, host: process.env.SERVER_HOST || '0.0.0.0' }, (err, address) => {
if (err) {
console.log(err)
fastify.log.error(err)
process.exit(1)
}
console.info(`Server listening on ${address}`)
fastify.log.info(`Server listening on ${address}`)
}))
.catch(console.log)

0 comments on commit 8bd36bb

Please sign in to comment.