diff --git a/api-01/src/index.js b/api-01/src/index.js index a033d72..8a98a67 100644 --- a/api-01/src/index.js +++ b/api-01/src/index.js @@ -37,16 +37,26 @@ app.use(cors(corsOptions)); app.use(auth); app.use(express.json()); // for parsing application/json //app.use(express.urlencoded({ extended: true })); -toInteger(process.env.API_LOG) - ? app.use( - morgan(morganOptions, { - stream: fs.createWriteStream(log.filePath, { flags: "a" }), - }) - ) - : null; app.use(helmet()); app.use(morgan(morganOptions)); +toInteger(process.env.API_CREATE_ADMIN) === 1 && + (async () => { + try { + const user = await service.createfirstUser(); + console.log(`First user created succesfully ${user}`); + } catch (error) { + console.log(`Error creating first user: ${error}`); + } + })(); + +toInteger(process.env.API_LOG) === 1 && + app.use( + morgan(morganOptions, { + stream: fs.createWriteStream(log.filePath, { flags: "a" }), + }) + ); + /*** * Routes */ @@ -59,16 +69,6 @@ app.post("/db-check", async (req, res) => { } }); -toInteger(process.env.API_CREATE_ADMIN) === 1 && - (async () => { - try { - const user = await service.createfirstUser(); - console.log(`First user created succesfully ${user}`); - } catch (error) { - console.log(`Error creating first user: ${error}`); - } - })(); - routerAPI(app); app.listen(process.env.API_PORT, () => {