diff --git a/templates/eject-esm/server.js b/templates/eject-esm/server.js index 7196ab2b..d9527b13 100644 --- a/templates/eject-esm/server.js +++ b/templates/eject-esm/server.js @@ -7,7 +7,7 @@ import closeWithGrace from 'close-with-grace' // Import your application import appService from './app.js' -// Dotenv config +// Read and load environment variables from .env files (ignore if not present) try { process.loadEnvFile() } catch {} @@ -17,7 +17,7 @@ const app = Fastify({ logger: true }) -// Register your application as a normal plugin. +// Register your application as a normal plugin app.register(appService) // delay is the number of milliseconds for the graceful close to finish @@ -28,7 +28,7 @@ closeWithGrace({ delay: process.env.FASTIFY_CLOSE_GRACE_DELAY || 500 }, async fu await app.close() }) -// Start listening. +// Start listening app.listen({ port: process.env.PORT || 3000 }, (err) => { if (err) { app.log.error(err) diff --git a/templates/eject-ts/server.ts b/templates/eject-ts/server.ts index 0fd28fa4..c4e44e1b 100644 --- a/templates/eject-ts/server.ts +++ b/templates/eject-ts/server.ts @@ -3,6 +3,8 @@ import Fastify from 'fastify' // Require library to exit fastify process, gracefully (if possible) import closeWithGrace from 'close-with-grace' + +// Read and load environment variables from .env files (ignore if not present) try { process.loadEnvFile() } catch {} @@ -12,7 +14,7 @@ const app = Fastify({ logger: true, }) -// Register your application as a normal plugin. +// Register your application as a normal plugin app.register(import('./app')) // delay is the number of milliseconds for the graceful close to finish @@ -23,7 +25,7 @@ closeWithGrace({ delay: parseInt(process.env.FASTIFY_CLOSE_GRACE_DELAY) || 500 } await app.close() } as closeWithGrace.CloseWithGraceAsyncCallback) -// Start listening. +// Start listening app.listen({ port: parseInt(process.env.PORT) || 3000 }, (err: any) => { if (err) { app.log.error(err) diff --git a/templates/eject/server.js b/templates/eject/server.js index 23e139d1..7593eb9d 100644 --- a/templates/eject/server.js +++ b/templates/eject/server.js @@ -1,6 +1,6 @@ 'use strict' -// Read the .env file. +// Read and load environment variables from .env files (ignore if not present) try { process.loadEnvFile() } catch {} @@ -16,7 +16,7 @@ const app = Fastify({ logger: true }) -// Register your application as a normal plugin. +// Register your application as a normal plugin const appService = require('./app.js') app.register(appService) @@ -28,7 +28,7 @@ closeWithGrace({ delay: process.env.FASTIFY_CLOSE_GRACE_DELAY || 500 }, async fu await app.close() }) -// Start listening. +// Start listening app.listen({ port: process.env.PORT || 3000 }, (err) => { if (err) { app.log.error(err)