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
Introducing Now and Next.js
Search
Naoyuki Kanezawa
November 13, 2016
Programming
5.7k
12
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Introducing Now and Next.js
now と next.js の紹介
Naoyuki Kanezawa
November 13, 2016
More Decks by Naoyuki Kanezawa
See All by Naoyuki Kanezawa
WebSocketの圧縮機能とSocket.IO
nkzawa
5
9.4k
Socket.IO 1.0 Client for Javaの紹介
nkzawa
5
1.9k
Socket.IO 1.0の変更点・内部的な話
nkzawa
20
9.4k
Other Decks in Programming
See All in Programming
パスワード再設定メールのURLについて知っておこう
uyuki234
0
120
Everything will be SERVERLESS — 信じて運用した10年の経験値 / Everything Will be Serverless — Lessons Learned from 10 Years of Operational Experience
seike460
PRO
1
960
CodeRabbitの効果検証と過ごしてみた3ヶ月
armondando
0
220
WebRTC映像をAirPlayに対応させる挑戦.pdf
monolithic_adam
0
350
Turning Architecture into Unit Tests in the AI Era (NSSpain XIV)
steliosf
PRO
1
140
[2026-09-26]空論ジェネリックプロセス~テスト資産とAIで紡ぐ、再現可能なパフォーマンスチューニングの話~
tosite
0
260
Augmenting AI with the Power of Jakarta EE
ivargrimstad
0
540
自サークルのIdPからログアウトできるようになるまで
taiseiue
1
130
HTML-in-Canvasで作る未来のWeb UI表現
clockmaker
3
4k
技術的負債の返済は、AI時代の複利で効く投資 — 経営としての意思決定とその遂行
curekoshimizu
1
2.3k
When benchmarks go bad - what I learned from measuring performance wrong
hollycummins
0
200
phperだってパンチカードでコーディングしたい
o0h
PRO
0
270
Featured
See All Featured
From π to Pie charts
rasagy
1
390
The MySQL Ecosystem @ GitHub 2015
samlambert
251
13k
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
35
2.9k
Imperfection Machines: The Place of Print at Facebook
scottboms
270
14k
Code Reviewing Like a Champion
maltzj
529
40k
A better future with KSS
kneath
240
18k
Groundhog Day: Seeking Process in Gaming for Health
codingconduct
0
400
XXLCSS - How to scale CSS and keep your sanity
sugarenia
250
1.3M
Ecommerce SEO: The Keys for Success Now & Beyond - #SERPConf2024
aleyda
1
2.2k
Measuring Dark Social's Impact On Conversion and Attribution
stephenakadiri
2
300
Embracing the Ebb and Flow
colly
88
5.2k
Abbi's Birthday
coloredviolet
4
10k
Transcript
Introducing Now and Next.js ౦ژNodeֶԂࡇ2016 @nkzawa
ࣗݾհ
@nkzawa Zeit, Inc ॴଐ next.js ϝϯςφ socket.io ϝϯςφ
Zeit ?
None
now micro hyper (چhyperterm) next.js
now micro hyper (چhyperterm) next.js
Next.js
ϢχόʔαϧͳReactΞϓϦͷͨΊͷখ͞ͳϑϨʔϜϫʔΫ
None
Get started 1. next.js ΛΠϯετʔϧ 2. next ίϚϯυΛ࣮ߦ 3. pages
σΟϨΫτϦʹ Reactίϯϙω ϯτΛฦ͢JSϑΝΠϧΛ࡞
ίϚϯυͰ͍͏ͱ $ npm install —save next $ node_modules/.bin/next $ vi
pages/index.js
pages/index.js import React from ‘react’ export default () => (
<div>Hello, world!</div> )
ϑΝΠϧΛURLʹϚοϐϯά pages/index.js -> / pages/about.js -> /about pages/foo/bar.js -> /foo/bar
ࣗಈͰ͜ΕΒ͕ߦΘΕΔ • αʔόϨϯμϦϯά • ίʔυׂ + Ԇಡࠐ • ࠷৽ίʔυࣗಈ࠶ಡࠐ(hot-code reloading)
• babelʹΑΔτϥϯεύΠϧ • webpackʹΑΔ݁߹
ઃఆͷඞཁͳ͠ ͔ͭ ։ൃɺύϑΥʔϚϯεΛ࠷దԽ
SPAͰΑ͋͘Δ • ॳظද͕͍ࣔ • ϖʔδ͕૿͑Δͱॏ͘ͳΔ
Next.jsͷղܾํ๏
αʔόϨϯμϦϯά ॳظදࣔύϑΥʔϚϯε্ɺSEO JSϑΝΠϧΛஔ͚ͩ͘
ϦονͳWebΞϓϦέʔγϣϯͷͨΊͷ7ͭͷݪଇ http://yosuke-furukawa.hatenablog.com/entry/2014/11/14/141415 “αʔόʔ͕ϖʔδΛϨϯμϦϯά͢ΔͷҙͰͳ͍ɻ” “tl;DR: αʔόʔϨϯμϦϯάSEO͚ͩͷͷ͡Όͳ͘ɺੑೳΛ্ͤ͞ΔͨΊͷͷ Ͱ͢ɻʢޙུʣ”
ίʔυׂ + Ԇಡࠐ ϖʔδຖʹ݁߹ϑΝΠϧΛ࡞͠ɺॳظදࣔ࣌ʹෆඞཁͳϞδϡʔϧಡΈࠐ·ͳ͍ɻ ભҠ͕ൃੜͨ͠ॠؒʹॳΊͯɺ࣍ͷίϯϙʔωϯτΛऔಘ͠දࣔ͢Δɻ ϖʔδಡΈࠐΉϞδϡʔϧ͕૿͑ͯɺଞͷϖʔδʹӨڹ͠ͳ͍ɻ
ͦͷଞͷػೳ
CSS glamor ϥΠϒϥϦΛͬͨελΠϧఆٛ - CSS-in-JS: JSͷදݱྗΛϑϧ׆༻ - ίϯϙωϯτຖʹಠཱ: ύϑΥʔϚϯεతʹଞϖʔδӨڹͳ͠ -
vendor prefix ࣗಈ༩ͷαϙʔτ
import React from 'react' import css from 'next/css' const style
= css({ background: ‘red’, ':hover': { background: 'gray' }, '@media (max-width: 600px)': { background: 'blue' } }) export default () => <p className={style}>hi!</p>
Link ίϯϙʔωϯτ pushState ΛͬͨϖʔδભҠ
import React from 'react' import Link from 'next/link' export default
() => ( <div><Link href=“/about”>͜͜</Link>ΛΫϦοΫ</div> )
Head ίϯϙʔωϯτ headλάͷࢠཁૉΛߋ৽
import React from 'react' import Head from 'next/head' export default
() => ( <div> <Head> <title>λΠτϧ</title> <meta charSet="utf-8" /> </Head> <p>hi</p> </div> )
getInitialProps τοϓϨϕϧίϯϙωϯτͷ props Λฦ͢staticϝιουΛఆٛ
IsomorphicʹσʔλΛऔಘ͢Δྫ import React from ‘react' import 'isomorphic-fetch' export default class
extends React.Component { static async getInitialProps () { // CORS͕༗ޮͳAPIʹαʔόɺΫϥΠΞϯτํ͔ΒΞΫηε const res = await fetch(‘http://api.example.com/user/123’) const user = await res.json() return { user } } render () { return <p>hi, {this.props.user.name}!</p> } }
ٞதͷIssue - Θ͔Γ͍͢URLͷ࣮ݱ /users/123 - babel, webpack ͷΧελϚΠζ ৄ͘͠: https://github.com/zeit/next.js#future-directions
Ұ୴·ͱΊ ReactΛ͍ͬͯΕ͙͢ʹ͑Δ Next.jsϑϩϯτΤϯυ։ൃΛָʹ͠·͢!
now
ΠϛϡʔλϒϧͳσϓϩΠαʔϏε
None
Get started 1. now ΛΠϯετʔϧ 2. now ίϚϯυΛ࣮ߦ͢Δ 3. ॳճͷΈϝʔϧʹΑΔϩάΠϯೝূ
ίϚϯυͰ͍͏ͱ $ npm install -g now $ now
package.json { “name”: “app” “scripts”: { “start”: “node server.js” }
}
ϙʔτΛҰͭͪड͚Δ const http = require(‘http’) http.createServer((req, res) => { res.writeHead(200,
{ 'Content-Type': ‘text/plain' }) res.end(‘Hello, world’) }).listen(3000, () => { console.log(‘Ready!’) })
ඞཁͳͷ npm start ͷఆٛͷΈ ͲͷϙʔτΛlistenͯ͠Α͍
શͯͷΞϓϦɺ͜ͷΑ͏ʹಈ࡞͢Δ • ৗʹHTTPS • ඪ४ͰHTTP/2αϙʔτ • Φʔτεέʔϧ • Πϛϡʔλϒϧ
ΠϛϡʔλϒϧɾσϓϩΠ σϓϩΠ͢Δຖʹ৽͍͠URL͕࡞͞ΕΔɻ ྫ͑: my-app-erkgfjtrna.now.sh ݹ͍URLআ͠ͳͯ͘Α͍ɻӬٱʹଘࡏ͠ଓ͚Δɻ
ຊ൪ެ։͢Δ࣌ʹɺΘ͔Γ͍͢ΤΠϦΞεɾυϝΠϯΛઃఆ $ now alias my-app-erkgfjtrna.now.sh my-app.now.sh
• URL͕ৗʹಉ͡ΞϓϦͷঢ়ଶΛද͢ • ߋ৽ϩʔϧόοΫ͕Ұॠ • εςʔδϯάڥ͕ඞཁͳ͘ͳΔ ͳͲͷར
Φʔτεέʔϧ τϥϑΟοΫϦιʔεͷมԽʹԠͯ͡ɺΠϯελϯεΛ૿ݮ τϥϑΟοΫΛෛՙࢄ
θϩͷεέʔϧ ͠Β͘τϥϑΟοΫ͕ͳ͍߹ɺΠϯελϯε͕θϩʹͳΔ ࠶ͼΞΫηε͕͋Εɺ৽ͨʹΠϯελϯε্ཱ͕͕ͪΔ
σʔλͷӬଓԽ Πϯελϯε͕ࣗಈͰੜɺഁغ͞ΕΔͨΊ෦ʹσʔλΛͤͳ͍ ΘΓʹ compose.com ͳͲͷΫϥυɾετϨʔδαʔϏεΛ͏
Dockerfile αϙʔτ package.json ͷΘΓʹ Dockerfile Λ༻ҙͯ͠ɺ $ now ͲΜͳݴޠͰॻ͔ΕͨΞϓϦσϓϩΠՄೳ
੩తαΠταϙʔτ htmlϑΝΠϧը૾ͳͲͷΞηοτΛ༻ҙͯ͠ɺ $ now ࣗಈͰ੩తαΠτ͔Ͳ͏͔ผ͞ΕΔ
ଞʹ • Now.app: σεΫτοϓɾΫϥΠΞϯτ • zeit.world: Free DNS αʔϏε •
now secret: γʔΫϨοτͷཧ
ϚΠΫϩαʔϏε micro ϥΠϒϥϦΛͬͨϢʔεέʔε https://github.com/zeit/micro
microΛͬͨαʔό࣮ const { json } = require(‘micro’) module.exports = async
(req, res) => { // ϦΫΤετϘσΟͷऔಘ const body = await json(req) console.log(body.data) // Ϩεϙϯε return { message: ‘ok’ } }
package.json { “name”: “foo”, “scripts”: { “start”: “micro” }, “dependencies”:
{ “micro”: “*” } }
σϓϩΠ & ΤΠϦΞεઃఆ $ now $ now alias foo-uiafeuzauf.now.sh foo.now.sh
ϚΠΫϩαʔϏε܈Λ࡞ foo.now.sh bar.now.sh baz.now.sh …
API GatewayͰ·ͱΊΔ api.my-app.com/foo -> foo.now.sh api.my-app.com/bar -> bar.now.sh api.my-app.com/baz ->
baz.now.sh …
Serverless ʹ͍ۙੑ࣭ (αʔόཧෆཁɺΦʔτεέʔϧɺؔɺ୯Ұͷؔ৺ࣄ) ʴ just HTTP (no ϩοΫΠϯ)
·ͱΊ now σϓϩΠΛγϯϓϧ͢Δ ˚ Zeit Node.JSΤίγεςϜʹߩݙ͍͖ͯ͠·͢