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
ONDA, Takashi
November 20, 2024
Programming
1.3k
1
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
2
160
細粒度リアクティブステートのスコープとライフサイクル
takonda
2
4.6k
React への依存を最小にするフロントエンド設計
takonda
27
29k
TSKaigi Kansai 2024 - 構造的部分型と serialize 境界
takonda
3
1.7k
Remix Way を外れる自由
takonda
2
630
一休レストランで 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
ビジネスモデルから紐解く、AI+型駆動開発
hirokiomote
2
4.6k
今さら聞けないCancellationToken
htkym
0
210
AI時代のUIはどこへ行く?その2!
yusukebe
15
4.6k
Copilot CLI の継戦能力を高める コンテキスト管理
nozomutu
1
1.1k
Augmenting AI with the Power of Jakarta EE
ivargrimstad
0
410
The Arts and Crafts of Work in the AI Era — Toward Mastery in Software Development
kuranuki
1
680
肥大化するレガシーコードに立ち向かうためのインターフェース分離と依存の逆転 / JJUG CCC 2026 Spring
hirokunimaeta
0
270
初めてのRubyKaigiはこう見えた
jellyfish700
0
370
Lemonade + Foundry Toolkit でお手軽アプリ開発
seosoft
1
250
Modding RubyKaigi for Myself
yui_knk
0
820
ふつうのFeature Flag実践入門
irof
7
3.4k
Transactional Change Stream Processing With Debezium and Apache Flink
gunnarmorling
1
140
Featured
See All Featured
Documentation Writing (for coders)
carmenintech
77
5.4k
The Illustrated Children's Guide to Kubernetes
chrisshort
51
52k
Believing is Seeing
oripsolob
1
140
StorybookのUI Testing Handbookを読んだ
zakiyama
31
6.8k
Deep Space Network (abreviated)
tonyrice
0
160
Java REST API Framework Comparison - PWX 2021
mraible
34
9.3k
Collaborative Software Design: How to facilitate domain modelling decisions
baasie
1
230
How People are Using Generative and Agentic AI to Supercharge Their Products, Projects, Services and Value Streams Today
helenjbeal
1
200
sira's awesome portfolio website redesign presentation
elsirapls
0
270
SEO in 2025: How to Prepare for the Future of Search
ipullrank
3
3.5k
Paper Plane (Part 1)
katiecoart
PRO
0
8.1k
ラッコキーワード サービス紹介資料
rakko
1
3.5M
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 エンジニア募集中! 一休では、よりよいサービスを届ける仲間を募集しています。