Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Remix で middleware
Search
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
ONDA, Takashi
November 20, 2024
Programming
1.1k
0
Share
Remix で middleware
Remix で middleware を作る方法とハマリどころ
ONDA, Takashi
November 20, 2024
More Decks by ONDA, Takashi
See All by ONDA, Takashi
Make Illegal States Unrepresentable
takonda
1
130
細粒度リアクティブステートのスコープとライフサイクル
takonda
2
4k
React への依存を最小にするフロントエンド設計
takonda
27
28k
TSKaigi Kansai 2024 - 構造的部分型と serialize 境界
takonda
3
1.6k
Remix Way を外れる自由
takonda
2
610
一休レストランで Next.js App Router から Remix に乗り換えた話 / Migration from Next.js App Router to Remix
takonda
14
8.7k
Other Decks in Programming
See All in Programming
Xdebug と IDE による デバッグ実行の仕組みを見る / Exploring-How-Debugging-Works-with-Xdebug-and-an-IDE
shin1x1
0
380
Liberating Ruby's Parser from Lexer Hacks
ydah
2
1.1k
第3木曜LT会 #28
tinykitten
PRO
0
110
ソフトウェア設計の結合バランス #phperkaigi
kajitack
0
110
2026_04_15_量子計算をパズルとして解く
hideakitakechi
0
110
PicoRuby for IoT: Connecting to the Cloud with MQTT
yuuu
2
420
UIの境界線をデザインする | React Tokyo #15 メイントーク
sasagar
2
360
YJITとZJITにはイカなる違いがあるのか?
nakiym
0
220
JOAI2026 1st solution - heron0519 -
heron0519
0
130
CDK Deployのための ”反響定位”
watany
4
760
実践CRDT
tamadeveloper
0
560
TiDBのアーキテクチャから学ぶ分散システム入門 〜MySQL互換のNewSQLは何を解決するのか〜 / tidb-architecture-study
dznbk
1
180
Featured
See All Featured
The SEO Collaboration Effect
kristinabergwall1
0
420
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
34
2.7k
Bioeconomy Workshop: Dr. Julius Ecuru, Opportunities for a Bioeconomy in West Africa
akademiya2063
PRO
1
94
SEO for Brand Visibility & Recognition
aleyda
0
4.5k
Have SEOs Ruined the Internet? - User Awareness of SEO in 2025
akashhashmi
0
320
Mozcon NYC 2025: Stop Losing SEO Traffic
samtorres
0
200
Building Better People: How to give real-time feedback that sticks.
wjessup
370
20k
Documentation Writing (for coders)
carmenintech
77
5.3k
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
333
22k
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
254
22k
Building a Modern Day E-commerce SEO Strategy
aleyda
45
9k
Embracing the Ebb and Flow
colly
88
5k
Transcript
Remix で middleware 株式会社一休 CTO 室 恩田 崇
2 自己紹介 株式会社一休 CTO 室 恩田 崇 1978 年生まれ、京都在住 フルスタック、なんでも屋
一休レストランのフロントエンドアーキテクト Next.js App Router を Remix に書き換えた フロントエンドは IE4/DHTML あたりから
3 TSKaigi Kansai にて TypeScript っぽい話をしたのに…
4 TSKaigi Kansai にて Remix 移行の話ばかりでした 🤣 懇親会その他で訊かれるのは…
5 本編 とある開発中の案件で認証関連の機能が必要に
6 本編 express だし middleware 使えばすぐ? 🤔 とある開発中の案件で認証関連の機能が必要に
7 middleware Remix は express アプリ const port = Number(process.env.PORT)
const buildPathArg = process.argv[2] const buildPath = path.resolve(buildPathArg) const build: ServerBuild = await import(url.pathToFileURL(buildPath).href) const app = express() app.disable('x-powered-by') app.use(compression()) // ここで middleware app.use(authMiddleware) app.use( build.publicPath, express.static(build.assetsBuildDirectory, { immutable: true, maxAge: '1y' }) ) app.all('*', remixHandler(build)) app.listen(port, onListen)
8 middleware Remix context に引き継げる function remixHandler(build: ServerBuild) { return
(req: Request, res: Response, next: NextFunction) => { const handler = createRequestHandler({ build, mode: process.env.NODE_ENV, getLoadContext() { return { authResult: (req as ReqWithAuth).authResult } }, }) handler(req, res, next) } }
9 ハマりどころ
10 ハマりどころ Node の native fetch でリクエストが詰まる問題に遭遇しました installGlobals を忘れずに `
` import { installGlobals } from '@remix-run/node' installGlobals() let { File: RemixFile, fetch: RemixFetch, FormData: RemixFormData, Headers: RemixHeaders, Request: RemixRequest, Response: RemixResponse, } = require("@remix-run/web-fetch"); global.File = RemixFile; global.Headers = RemixHeaders; global.Request = RemixRequest; global.Response = RemixResponse; global.fetch = RemixFetch; global.FormData = RemixFormData;
11 2024 年に express 書くの? 今日の特別ゲストは…
12 2024 年に express 書くの? 今日の特別ゲストは…
13 2024 年に express 書くの? demo hono-remix-adapter で動かしてみた
14 宣伝 土曜日の JSConf JP で登壇します
15 エンジニア募集中! 一休では、よりよいサービスを届ける仲間を募集しています。