Update eject example to something more robust
还没有人认领这个 Issue。
评估
- 难度
- 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
pluginsand 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 小时
- 30 天内合并 PR
- 2
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
fastify/fastify-cli 的其他 Issue
-
难度 5/5 一周以上 新手友好度 35/100
fastify/fastify-cli#846 · 2 条评论 ·
-
难度 5/5 一周以上 新手友好度 25/100
fastify/fastify-cli#841 ·
-
Generated Fastify ESM/TS app has broken `npm test` command (FASTIFY_AUTOLOAD_TYPESCRIPT)可能已有人在做 @GhaythBenAbid 于 28 天前认领。 未关闭
难度 3/5 1-2 天 新手友好度 45/100
fastify/fastify-cli#835 · 2 条评论 ·
-
Adding Path Alias Support in fastify-cli可能重新可做 @ali139713 于 51 天前认领,目前没有进行中的 PR。 未关闭
难度 4/5 3-5 天 新手友好度 52/100
fastify/fastify-cli#806 · 1 条评论 · 7 个 reaction ·
-
Only watch specified directory (--watch CLI param)可能已有人在做 @josephreilly22 于 241 天前认领。 未关闭good first issue
难度 3/5 1-2 天 新手友好度 38/100
fastify/fastify-cli#787 · 5 条评论 · 2 个 reaction ·
查看 fastify/fastify-cli 的全部 Issue
相似的 Issue
-
docs hacktoberfest help wanted
难度 2/5 1-3 小时 新手友好度 85/100
pacocartones/free-llm-api-hub#347 ·
维护者通常 1 天内回复
-
bug
难度 2/5 1-3 小时 新手友好度 72/100
cytoscape/cytoscape.js#3536 ·
维护者通常 15 天内回复
-
难度 2/5 1-3 小时 新手友好度 72/100
cuttle-cards/cuttle#1440 ·
维护者通常 1 天内回复
-
URL-encoded parser builds nested objects nothing reads可能已有人在做 @Senthil455 今天认领。 未关闭
难度 1/5 1 小时以内 新手友好度 82/100
Janani-bn/CivicFix#168 · 1 条评论 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 62/100
code-yeongyu/oh-my-openagent#10172 ·
维护者通常 1 天内回复