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
Rails5 APIではじめるSPA開発
Search
hatappi
July 14, 2016
Technology
1
1.4k
Rails5 APIではじめるSPA開発
hatappi
July 14, 2016
Tweet
Share
More Decks by hatappi
See All by hatappi
RubyではじめるGraphQL
hatappi
0
770
RubyでChainerつくってます!!
hatappi
2
1.3k
TDDな個人開発
hatappi
0
260
できるだけ楽して楽しくRails開発しよう
hatappi
2
290
EKSにRailsをのせた
hatappi
1
1.1k
RubyとApache Arrow
hatappi
0
2.1k
Red Chainerを なぜ作って今後どうするのか
hatappi
2
2.2k
Fargateで夢は見られるのか
hatappi
1
2k
個人サービスをFargateに移行したよ
hatappi
1
620
Other Decks in Technology
See All in Technology
Lexical Analysis
shigashiyama
1
150
CysharpのOSS群から見るModern C#の現在地
neuecc
2
3.2k
Evangelismo técnico: ¿qué, cómo y por qué?
trishagee
0
360
RubyのWebアプリケーションを50倍速くする方法 / How to Make a Ruby Web Application 50 Times Faster
hogelog
3
940
VideoMamba: State Space Model for Efficient Video Understanding
chou500
0
190
Why App Signing Matters for Your Android Apps - Android Bangkok Conference 2024
akexorcist
0
120
個人でもIAM Identity Centerを使おう!(アクセス管理編)
ryder472
3
200
Adopting Jetpack Compose in Your Existing Project - GDG DevFest Bangkok 2024
akexorcist
0
110
[CV勉強会@関東 ECCV2024 読み会] オンラインマッピング x トラッキング MapTracker: Tracking with Strided Memory Fusion for Consistent Vector HD Mapping (Chen+, ECCV24)
abemii
0
220
New Relicを活用したSREの最初のステップ / NRUG OKINAWA VOL.3
isaoshimizu
2
590
AWS Lambda のトラブルシュートをしていて思うこと
kazzpapa3
2
170
Taming you application's environments
salaboy
0
180
Featured
See All Featured
A Modern Web Designer's Workflow
chriscoyier
693
190k
Designing for humans not robots
tammielis
250
25k
Ruby is Unlike a Banana
tanoku
97
11k
A better future with KSS
kneath
238
17k
How to train your dragon (web standard)
notwaldorf
88
5.7k
Documentation Writing (for coders)
carmenintech
65
4.4k
Become a Pro
speakerdeck
PRO
25
5k
How STYLIGHT went responsive
nonsquared
95
5.2k
Put a Button on it: Removing Barriers to Going Fast.
kastner
59
3.5k
What's new in Ruby 2.0
geeforr
343
31k
Reflections from 52 weeks, 52 projects
jeffersonlam
346
20k
A designer walks into a library…
pauljervisheath
203
24k
Transcript
Rails5Ͱߦ͏SPA։ൃ Roppongi.rb #1
ࣗݾհ —໊લ : ാத༔࡞ —Twitter : @hatappi —ձࣾ : גࣜձࣾSpeee
—৬ : ίʔώʔ
None
SPAͱʁ
SinglePageApplicaton ӳޠͦͷ··Ͱ୯ҰϖʔδͰߏ͞ΕͨΞϓϦέʔγϣ ϯ ࠷ॳϖʔδશମΛಡΈࠐΜͩޙjavascriptͰඞཁͳ෦ Λߋ৽͍ͯ͘͠ σʔλ࿈ܞAjaxWebSocketʹͯߦ͏
Πϯϑϥߏ
None
GCP (GoogleCloudPlatform) —CDNΛ͏ࡍʹAWSͩͱ S3+CloudFront GCPͰStorageʹΞοϓϩʔ υͯ͠ACLͷઃఆΛมߋ͢Ε ެ։Ͱ͖Δ —੩తwebαΠτΛϗεςΟϯά Ͱ͖ΔͷͰαʔόʔϨεӡ༻͕ Մೳ!
Angular2 Googleͷ։ൃ͢ΔJavascriptͷϑ ϨʔϜϫʔΫ ݱঢ়rc4 React͕ViewͷίϯϙʔωϯτΛ ఏڙ͢Δͷʹରͯ͠MVCΛఏڙ͢ ΔϑϧελοΫͳϑϨʔϜϫʔΫ
Rails5ͷ ࠓͷϝΠϯ RubyͷwebΞϓϦέʔγϣϯɾϑ ϨʔϜϫʔΫ 7/1ʹrc͕ͱΕ͍ͯͭʹ5͕ϦϦʔ ε!
None
Rails5Ͱͷมߋ —Action Cable —rakeλεΫΛrailsͰ࣮ߦ —turbolinks5 —sprockets3 —rails api
Rails5Ͱͷมߋ —Action Cable —rakeλεΫΛrailsͰ࣮ߦ —turbolinks5 —sprockets3 —rails api <- ࠓ͜͜
Rails API ݩʑgemͩͬͨrails-api͕RailsʹϚʔδ͞Εͨ —helperassets, views͕ͬͦ͝Γফ͑ͯΔ —cookieͱ͔session storeͷఆٛͳ͍ —config͔Βassetؔ࿈ͷͷ͕ͳ͘ͳ͍ͬͯΔ
γϯϓϧ!
Rails apiͷͱ͖ʹ͋ͨͬͨ՝ —view͕΄͘͠ͳͬͨΒ —CORS —Ϣʔβʔೝূ
Rails apiͷͱ͖ʹ͋ͨͬͨ՝ —view͕΄͘͠ͳͬͨΒ —CORS —Ϣʔβʔೝূ
ͬͺΓView͕΄͍͠ɾɾ
Viewޙ͔ΒͰՃͰ͖Δ ඞཁͳmiddlewareΛՃͯ͋͛͠ΕݩͷඇAPIͷ Railsʹ͢Δ͜ͱग़དྷΔɻ ٯʹAPIʹ͢Δͷ͋ΔͷΛআ͍͔ͯ͠ͳ͍ͱ͍͚ ͳ͍ͷͰ݁ߏେม!
Rails apiͷͱ͖ʹ͋ͨͬͨ՝ —view͕΄͘͠ͳͬͨΒ —CORS —Ϣʔβʔೝূ
CORSͱ?
CORS (Cross-Origin Resource Sharing) SameOriginPolicyʹΑΓXHRͱ͔ Ͱࠓ͍ΔαΠτͱผͷαΠτ͔Β σʔλΛಡΈࠐΉͱΤϥʔʹͳ Δɻ ͦΕΛڐՄ͞ΕͨαΠτʹରͯ͠ OriginΛ͑ͯ͜ΞΫηε͑͞Δ
Έ
rack-cors (https://github.com/cyu/rack-cors) originsͰڐՄ͢ΔϗετΛઃఆ '*'͍͚Δ͚Ͳຊ൪ʹө͢Δͱ͖ҙ Rails.application.config.middleware.insert_before 0, Rack::Cors do allow do
origins 'roppongirb.com' resource '*', headers: :any, methods: [:get, :post, :put, :patch, :delete, :options, :head] end end
Rails apiͷͱ͖ʹ͋ͨͬͨ՝ —view͕΄͘͠ͳͬͨΒ —CORS —Ϣʔβʔೝূ
RailsApiͰcookie session͕ͦͬ͝ͱͳ͘ͳͬ ͯΔ!
cookieͰͳ͘tokenͰ ཧͩ❗❗
None
ೝূॲཧࣗମ GoogleOAuth2 Ͱߦ͍ͦͷޙτ ʔΫϯΛੜ
googleΛΘͣશ෦ࣗલͰߦ͏ͧͬͯํ —devise_token_auth deviseΛͬͯRailsͰTokenBasedͷೝূΛߦ͏ ͷ —doorkeeper RailsͰOAuth2ͷϓϩύΠμʔΛ͏ͨΊͷͷ
·ͱΊ
·ͱΊ —SPAා͘ͳ͍ —API modeʹͯ͠࠷ѱͤΔͷͰνϟϯϨϯδͯ͠ Έͯྑ͍͔ —turbolinksɺsprockets, coffeescriptͱ͍͏ݴ༿ʹർ Εͯ͠·ͬͨΒݕ౼ͯ͠ྑ͍͔