diff --git a/templates/eject-esm/server.js b/templates/eject-esm/server.js index d9527b13..2396d48d 100644 --- a/templates/eject-esm/server.js +++ b/templates/eject-esm/server.js @@ -5,7 +5,7 @@ import Fastify from 'fastify' import closeWithGrace from 'close-with-grace' // Import your application -import appService from './app.js' +import { app as serviceApp, options as serviceOptions} from './app.js' // Read and load environment variables from .env files (ignore if not present) try { @@ -13,12 +13,12 @@ try { } catch {} // Instantiate Fastify with some config -const app = Fastify({ +const app = Fastify(serviceOptions || { logger: true }) // Register your application as a normal plugin -app.register(appService) +app.register(serviceApp) // delay is the number of milliseconds for the graceful close to finish closeWithGrace({ delay: process.env.FASTIFY_CLOSE_GRACE_DELAY || 500 }, async function ({ signal, err, manual }) { diff --git a/templates/eject-ts/server.ts b/templates/eject-ts/server.ts index c4e44e1b..d6da1e62 100644 --- a/templates/eject-ts/server.ts +++ b/templates/eject-ts/server.ts @@ -4,18 +4,21 @@ import Fastify from 'fastify' // Require library to exit fastify process, gracefully (if possible) import closeWithGrace from 'close-with-grace' +// Import your application +import { app as serviceApp, options as serviceOptions} from './app.ts' + // Read and load environment variables from .env files (ignore if not present) try { process.loadEnvFile() } catch {} // Instantiate Fastify with some config -const app = Fastify({ +const app = Fastify(serviceOptions || { logger: true, }) // Register your application as a normal plugin -app.register(import('./app')) +app.register(serviceApp) // delay is the number of milliseconds for the graceful close to finish closeWithGrace({ delay: parseInt(process.env.FASTIFY_CLOSE_GRACE_DELAY) || 500 }, async function ({ signal, err, manual }) { diff --git a/templates/eject/server.js b/templates/eject/server.js index 7593eb9d..e24f293b 100644 --- a/templates/eject/server.js +++ b/templates/eject/server.js @@ -11,14 +11,15 @@ const Fastify = require('fastify') // Require library to exit fastify process, gracefully (if possible) const closeWithGrace = require('close-with-grace') +// Register your application as a normal plugin. +const appService = require('./app.js') + // Instantiate Fastify with some config -const app = Fastify({ +const app = Fastify(appService.options || { logger: true }) -// Register your application as a normal plugin -const appService = require('./app.js') -app.register(appService) +app.register(appService.app) // delay is the number of milliseconds for the graceful close to finish closeWithGrace({ delay: process.env.FASTIFY_CLOSE_GRACE_DELAY || 500 }, async function ({ signal, err, manual }) {