Hacktoberfest 2026: die Issues, die Maintainer für den Oktober markiert haben – offen und einsteigerfreundlich. Hacktoberfest-Issues durchsuchen

Update eject example to something more robust

Offen
#616 4 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

Bewertung

Schwierigkeit
2/5
Geschätzter Aufwand
1-3 Stunden
Anfängerfreundlichkeit
35/100
Issue-Typ
Dokumentation
Klarheit
Größtenteils klar
Aktivitätsstatus
Veraltet
Tech-Stack
node.js, typescript
Bereich
cli, documentation

Rechercherichtung

Das Issue nennt weder die Eject-Template-Datei noch einen Test; beginne damit, das Eject-Beispiel in fastify-cli zu finden und zu untersuchen, wie die generierte App Plugins registriert und den Server startet. Aktualisiere das Beispiel so, dass es die Registrierung vor dem Lauschen validiert und .ready() zeigt; fertig ist es, wenn das generierte Beispiel diesen Ablauf widerspiegelt und die relevanten Prüfungen erfolgreich sind.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

Prerequisites
  • I have written a descriptive issue title
  • I have searched existing issues to ensure the feature has not already been requested
🚀 Feature Proposal

Change the eject file example to validate everything before running the server and make use of the .ready() function.

Motivation

What made me think of this approach are:

  • Fastify encapsulation concept, the server should not run if something goes wrong with plugins and are not loaded inside correctly inside Fastify.
  • The struggle I've been in the past few days trying to use Fastify in a complex real-world project and I didn't find clear examples.
  • easier to handle errors, if something goes wrong Fastify will throw the valid error not some error buried deep inside the router or hooks
  • the unclear error "cannot read properties of undefined (reading 'length')" which was happening for several reasons and I cannot detect them until i throw error on startup
Example
// Read the .env file.
import * as dotenv from "dotenv";
dotenv.config();

// Require the framework
import Fastify from "fastify";

// Require library to exit fastify process, gracefully (if possible)
import closeWithGrace from "close-with-grace";

// Instantiate Fastify with some config
const app = Fastify({
  logger: true,
});
// make use of the `.ready()` to prevent going on race condition
fastify.register(app).ready((err) => {
   // throw error if something happened on registering `plugins` or `routes`
	if (err) throw err;
	// delay is the number of milliseconds for the graceful close to finish
	const closeListeners = closeWithGrace(
		{
			delay:
				parseInt(process.env.FASTIFY_CLOSE_GRACE_DELAY as string) ||
				500,
		},
		async function ({ signal, err, manual }) {
			if (err) {
				fastify.log.error(err);
			}
			await fastify.close();
		} as closeWithGrace.CloseWithGraceAsyncCallback
	);
	fastify.addHook("onClose", async (instance, done) => {
		closeListeners.uninstall();
		done();
	});
	//server listen
	const port = process.env.PORT || 8000;
	// Start listening.
	fastify.listen({ port: parseInt(port as string) }, (err: any) => {
		if (err) {
			fastify.log.error(err);
			process.exit(1);
		}
	});
});
Vorherrschende Sprache
JavaScript
Sterne
733
Forks
179
Ø Merge
8 T. 12 Std.
Gemergte PRs (30 T.)
2

Entwicklungsumgebung

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus fastify/fastify-cli

Alle Issues in fastify/fastify-cli

Ähnliche Issues

Weitere Issues zu JavaScript

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.