Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

Update eject example to something more robust

オープン
#616 コメント 4 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
35/100
issue の種類
ドキュメント
明瞭さ
おおむね明確
活発さ
停滞
技術スタック
node.js, typescript
領域
cli, documentation

調査の方向性

この issue には eject のテンプレートファイルもテストも記載されていません。まず fastify-cli 内の eject の例を見つけ、生成されたアプリがどのようにプラグインを登録してサーバーを起動するかを確認してください。登録をリッスン開始前に検証し、.ready() を示すように例を更新してください。生成された例がこのフローを反映し、関連するチェックが通れば完了です。

索引モデルが issue の本文から書いたものです。

説明

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);
		}
	});
});
主要言語
JavaScript
スター
733
フォーク
179
平均マージ
8日 12時間
マージ済み PR(30日)
2

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

fastify/fastify-cli のほかの issue

fastify/fastify-cli の issue をすべて見る

似ている issue

JavaScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。