From 8bd36bb74f8b7fd0af84bfac63dec2c74317c034 Mon Sep 17 00:00:00 2001 From: apiyo Date: Thu, 11 May 2023 11:24:02 +0300 Subject: [PATCH] Add ternary operator to check if CORS_ORIGIN is string and remove console.log --- index.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index ea7b3b2..8ec9bae 100644 --- a/index.js +++ b/index.js @@ -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) { @@ -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) { @@ -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)