Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Remix で middleware
Search
ONDA, Takashi
November 20, 2024
Programming
1.5k
1
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Remix で middleware
Remix で middleware を作る方法とハマリどころ
ONDA, Takashi
November 20, 2024
Transcript
15 slides
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 エンジニア募集中! 一休では、よりよいサービスを届ける仲間を募集しています。
More Decks by ONDA, Takashi
See All by ONDA, Takashi
Rust で関数型ドメインモデリング
takonda
0
230
Make Illegal States Unrepresentable
takonda
2
270
細粒度リアクティブステートのスコープとライフサイクル
takonda
2
6.9k
React への依存を最小にするフロントエンド設計
takonda
28
29k
TSKaigi Kansai 2024 - 構造的部分型と serialize 境界
takonda
3
1.8k
Remix Way を外れる自由
takonda
2
670
一休レストランで Next.js App Router から Remix に乗り換えた話 / Migration from Next.js App Router to Remix
takonda
14
8.9k
Other Decks in Programming
See All in Programming
AWS CDKを理解するために公式の定義を深掘って解説してみる / Understanding AWS CDK by Digging into Its Official Definition
akihisaikeda
3
310
[DroidKnights 2026] Workflow AX: From Auto-Documented Policies to E2E Testing
raeminkang
0
570
TS 7.0 で baseUrl が使えなくなった今、パスエイリアスをどうするか
bicstone
2
660
止まらない比較を止める — 余帰納法で無限ストリームを比べる
tarao
0
160
Zero-Tap Sign-In対応、結局何をすればいいの?
mitohato14
0
2.1k
Railsのためのパスキー実践入門 〜マルチテナントSaaSでの意思決定〜
utakaha
4
4.5k
AI時代のシニアエンジニアとは
yosuke_furukawa
PRO
15
12k
protojson における文字化けの扱い
kazuki1023
0
430
AI時代のIaC入門 〜なぜインフラをコードで管理したいのか?〜 / Introduction to IaC in the AI Era
akihisaikeda
6
1.5k
From Java 8-11 to Java 21-27 — Benefits, Challenges, and a Practical Migration Path
x5gtrn
PRO
0
100
Secure Your Coding Agent Like It’s Malware (v1.5) 🇬🇧 @Code.talks 2026
richargh
0
150
Web3Dライブラリを作ってVue Custom Rendererの仕組みを理解しよう / lets learn vue custom renderer by making 3d library
drumath2237
1
140
Featured
See All Featured
Highjacked: Video Game Concept Design
rkendrick25
PRO
2
570
Kristin Tynski - Automating Marketing Tasks With AI
techseoconnect
PRO
0
590
svc-hook: hooking system calls on ARM64 by binary rewriting
retrage
2
680
The Language of Interfaces
destraynor
162
27k
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
508
140k
Fashionably flexible responsive web design (full day workshop)
malarkey
409
67k
30 Presentation Tips
portentint
PRO
1
470
The Invisible Side of Design
smashingmag
301
52k
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
12
1.4k
Technical Leadership for Architectural Decision Making
baasie
4
650
How to Grow Your eCommerce with AI & Automation
katarinadahlin
PRO
2
350
Automating Front-end Workflow
addyosmani
1370
210k