Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

koaやめる #7537

Closed
syuilo opened this issue May 27, 2021 · 76 comments · Fixed by #9106
Closed

koaやめる #7537

syuilo opened this issue May 27, 2021 · 76 comments · Fixed by #9106
Assignees
Labels
🔥high priority packages/backend Server side specific issue/PR 💚Refactor Rewriting code without changing behavior

Comments

@syuilo
Copy link
Member

syuilo commented May 27, 2021

Summary

TypeScriptネイティブではないので、型定義上の問題が起きやすく不便

@syuilo syuilo added packages/backend Server side specific issue/PR 💚Refactor Rewriting code without changing behavior labels May 27, 2021
@syuilo
Copy link
Member Author

syuilo commented May 27, 2021

良い代替のフレームワークなさそう

@tamaina
Copy link
Member

tamaina commented May 27, 2021

@mei23 がまえにkoaやめる話をしてた気がする

@mei23
Copy link
Contributor

mei23 commented May 27, 2021

前Fastify使おうとしていた
mei23#2285

@rinsuki
Copy link
Contributor

rinsuki commented Jun 2, 2021

これとかどうだろう https://github.com/talentlessguy/tinyhttp

@syuilo
Copy link
Member Author

syuilo commented Jun 8, 2021

tinyhttpにしてみるか

@syuilo syuilo changed the title koaやめたい koaやめてtinyhttpにする Jun 8, 2021
@syuilo
Copy link
Member Author

syuilo commented Aug 15, 2021

やたら「express互換だよ!express replacementだよ!」ってアピールされているのがちょっと気になる
別にexpressにこだわり無いから…

@syuilo syuilo changed the title koaやめてtinyhttpにする koaやめる Aug 17, 2021
@syuilo
Copy link
Member Author

syuilo commented Aug 17, 2021

tinyhttpこの間使ったけどなんかバグ踏んで散々な目にあった
tinyhttp/tinyhttp#279
@rinsuki

Fastifyバグっぽいのはあったことないけど、TypeScriptネイティブじゃないからTypeScriptでどう書くの~って悩む所はちょこちょこあったのだわ。
@mei23@misskey.m544.net

@mei23
Copy link
Contributor

mei23 commented Aug 17, 2021

tinyhttp/tinyhttp#279

そういえばkoa-routerも同ルートで変なとこあった気がした
#6533

@syuilo syuilo added the 💬Discussion Being discussed or needs discussion label Aug 17, 2021
@sousuke0422
Copy link
Contributor

tinyhttpはv2で完全なESMに移行したらしい
https://github.com/tinyhttp/tinyhttp/releases/tag/%40tinyhttp%2Fapp%402.0.0

@syuilo syuilo pinned this issue Sep 18, 2021
@syuilo
Copy link
Member Author

syuilo commented Sep 18, 2021

なんでHTTPフレームワークでデータベースの話が出てくるんだろう
fastify/fastify#3005

@syuilo
Copy link
Member Author

syuilo commented Sep 18, 2021

fastifyの型が完全じゃないことがあるというのは明記されてた

As the team works on improving framework and type definition synergy, sometimes parts of the API will not be typed or may be typed incorrectly

@syuilo
Copy link
Member Author

syuilo commented Sep 18, 2021

でもfastifyの方がメジャーではあるんだよな

@mei23
Copy link
Contributor

mei23 commented Sep 18, 2021

tinyhttpのサイトって重かったり落ちてたりするからなんだか

@mei23
Copy link
Contributor

mei23 commented Sep 18, 2021

express/koa/tinyhttpあたりのexpress系にあるnext()を呼ぶというのがわかりづらくて嫌いなので、その概念がないFastifyの方が好き。

@syuilo
Copy link
Member Author

syuilo commented Sep 18, 2021

Fastifyでやってみるか

@syuilo
Copy link
Member Author

syuilo commented Sep 18, 2021

型で困らないことを祈る

@rinsuki
Copy link
Contributor

rinsuki commented Sep 18, 2021

fastify なんかバリデーションとかまで入ってて壮大で、そうじゃないんだよな…感あった (いまさら)

@syuilo
Copy link
Member Author

syuilo commented Sep 18, 2021

それは思った
ちょっと機能が多すぎな感じはある

@syuilo
Copy link
Member Author

syuilo commented Oct 16, 2021

バックエンド全体の話になるけどNest.jsとか導入するのはどうだろうと思ってた
んだけど、試した感じ

  • 事実上express使うことを余儀なくされる
  • Nest.jsがそこら辺(express)を抽象化してくれる訳でもないため、express由来の型エラーに悩まされることも多かった
  • REST APIを想定していて、Misskeyには合わなそう
  • エラーが握りつぶされることがあり、デバッグに手間取った
  • ドキュメントの情報量が多くて学習コストがかなり高い
  • これはNest.jsというよりデザインパターンの話だけど、「ノートをお気に入り登録するのはNoteServiceに書くのか?FavoriteServiceに書くのか?」みたいな悩みが発生しがち

だから微妙な感じした
使いこなせれば今の状態より見通し良くなるかもしれないけど…

@syuilo
Copy link
Member Author

syuilo commented Oct 29, 2021

fastifyに移行するのも結構大変かも

@mei23
Copy link
Contributor

mei23 commented Oct 29, 2021

そう?

@syuilo
Copy link
Member Author

syuilo commented Oct 29, 2021

コード量というよりは対応する機能を探すのが大変そうと思った

@mei23
Copy link
Contributor

mei23 commented Oct 29, 2021

参考
https://github.com/mei23/misskey/pull/2285/files

fastifyStatic => koa_send みたいなの
pointOfView: view(pug) あたり
基本headerは先にsetする
next()で流れ落ちみたいな概念はないので、/users/:id みたいな APとWebでAccpetで出し分ける場所は1つのroute内で分岐になる?

@syuilo
Copy link
Member Author

syuilo commented Nov 5, 2021

@syuilo
Copy link
Member Author

syuilo commented Sep 28, 2022

あと必ずルートで宣言しなければならないというのはFastifyの掲げるカプセル化の思想と逆行するわね(プラグイン内で定義で来てほしい)

👀 fastify/fastify#3615

ちょっと違う話っぽい(プラグイン全体に制約を「適用」したいという話で、プラグイン内に制約を「定義」したい話ではなさそう)

@acid-chicken
Copy link
Member

fastify.addConstraintStrategy でいけそう

@syuilo
Copy link
Member Author

syuilo commented Sep 28, 2022

fastify.addConstraintStrategy でいけそう

ちょうど見てた
thx

@syuilo
Copy link
Member Author

syuilo commented Sep 28, 2022

でもやっぱり

Property 'validate' is missing in type '{ name: string; ...

エラーが出る

@syuilo
Copy link
Member Author

syuilo commented Sep 28, 2022

validate なんてプロパティドキュメントのどこにもないんだけど

@syuilo
Copy link
Member Author

syuilo commented Sep 28, 2022

げっ、しかも deriveConstraint の req って IncomingMessage じゃん
そうすると@fastify/acceptsとかが使えない...

@syuilo
Copy link
Member Author

syuilo commented Sep 28, 2022

tasukete

@acid-chicken
Copy link
Member

acid-chicken commented Sep 28, 2022

validate なんてプロパティドキュメントのどこにもないんだけど

これはなんか型の書き間違えっぽそう

げっ、しかも deriveConstraint の req って IncomingMessage じゃん そうすると@fastify/acceptsとかが使えない...

まあ @fastify/acceptsaccepts のラッパっぽいし直接呼べばよさそう

@syuilo
Copy link
Member Author

syuilo commented Sep 28, 2022

ドキュメントでは deriveConstraint ってなってたり deriveVersions ってなってたり型定義では validate ってなってたりどれが正解なんだ

@syuilo
Copy link
Member Author

syuilo commented Oct 12, 2022

ヌァァァァァァァァァァァァァァァァァァァァァァァァァァァァァァァァァァンンンンオオオオンンオンオンオンオンンンンンンンンン゛ン゛!!!!!!!!!!!!!!!!

@syuilo
Copy link
Member Author

syuilo commented Oct 13, 2022

nani
image

@syuilo
Copy link
Member Author

syuilo commented Oct 13, 2022

どんなURLにしてもnot foundになるんだけど

@syuilo
Copy link
Member Author

syuilo commented Oct 13, 2022

tasukete

@syuilo
Copy link
Member Author

syuilo commented Oct 13, 2022

あとこれが出る
image

@syuilo
Copy link
Member Author

syuilo commented Oct 14, 2022

preParsingフックなんて使ってないのになぜpreParsing処理を呼ぼうとしてるんだ

@syuilo
Copy link
Member Author

syuilo commented Oct 14, 2022

これだけ単純化しても同じエラー出る

const fastify = Fastify({});

fastify.get('/hello', async (request, reply) => {
	return 'world!';
});

fastify.server.listen(this.config.port);

@syuilo
Copy link
Member Author

syuilo commented Oct 14, 2022

fastify.server.listen(this.config.port);

fastify.listen({ port: this.config.port });

にしたら直った

@syuilo
Copy link
Member Author

syuilo commented Oct 14, 2022

なんか Route Prefixing が機能してないような気がする

@syuilo
Copy link
Member Author

syuilo commented Oct 14, 2022

🤯
image

@syuilo
Copy link
Member Author

syuilo commented Oct 14, 2022

エラーは出なくなったけどなんかレスポンスが返ってこない

@syuilo
Copy link
Member Author

syuilo commented Oct 14, 2022

直った

@syuilo
Copy link
Member Author

syuilo commented Oct 14, 2022

なぜか request.body が undefined になる

@syuilo
Copy link
Member Author

syuilo commented Oct 14, 2022

tasukete

@syuilo
Copy link
Member Author

syuilo commented Oct 19, 2022

なんも分からん

@syuilo
Copy link
Member Author

syuilo commented Oct 28, 2022

ヌァァァァァァァァァァァァァァァァァァァァァァァァァァァァァァァァァァンンンンオオオオンンオンオンオンオンンンンンンンンン゛ン゛!!!!!!!!!!!!!!!!

@syuilo
Copy link
Member Author

syuilo commented Oct 28, 2022

なぜか request.body が undefined になる

解決した方に報奨金を進呈

@syuilo
Copy link
Member Author

syuilo commented Nov 3, 2022

解決した

@tamaina
Copy link
Member

tamaina commented Nov 3, 2022

結局何が原因だったの?

@syuilo syuilo unpinned this issue Dec 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🔥high priority packages/backend Server side specific issue/PR 💚Refactor Rewriting code without changing behavior
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants