Skip to content

Commit cef99bc

Browse files
committed
Add ternary operator to check if CORS_ORIGIN is string and remove console.log
1 parent 0013eaf commit cef99bc

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

index.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ async function build() {
3636
}
3737
})
3838
.catch((error) => {
39-
console.log(error)
39+
req.log.error(err)
4040
done(error.detail);
4141
});
4242
} else if ("/health-check" == req.url) {
@@ -72,7 +72,7 @@ async function build() {
7272
})
7373

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

7777
// OPTIONAL RATE LIMITER
7878
if ("RATE_MAX" in process.env) {
@@ -130,9 +130,9 @@ build()
130130
.then(fastify => // LAUNCH SERVER
131131
fastify.listen({ port: process.env.SERVER_PORT || 3000, host: process.env.SERVER_HOST || '0.0.0.0' }, (err, address) => {
132132
if (err) {
133-
console.log(err)
133+
fastify.log.error(err)
134134
process.exit(1)
135135
}
136-
console.info(`Server listening on ${address}`)
136+
fastify.log.info(`Server listening on ${address}`)
137137
}))
138-
.catch(console.log)
138+
.catch(fastify.log.error)

0 commit comments

Comments
 (0)