Share
Embed
Transcript
45 slides
-
͜͡͠ΐ͏͔͍ • SCOUTER CTO • جຊΠϯϑϥɺόοΫΤϯυ • جຊLaravel 5.4 or
5.5, Vue.js 2.4 or 2.5Ͱ։ൃ • -
Web৬ਓͷͨΊͷϑϨʔϜϫʔΫ • ˑ36,323 • Web։ൃͰ༻͢Δ͞·͟·ͳجຊػೳΛଟࡌͨ͠ॏྔڃPHPϑ ϨʔϜϫʔΫ • ORMɺϧʔςΟϯάɺδϣϒΩϡʔɺ௨ɺϚΠάϨʔγϣϯ etc.. •
ॆ࣮ͨ͠υΩϡϝϯτ • https://laravel.com ެࣜ • https://readouble.com/ ຊޠ -
Progressive JS Framework • ˑ74,322 • HTMLϑΝΠϧͷΑ͏ͳهड़Ͱॻ͚Δ • पลϥΠϒϥϦͱͷซ༻ͰSPASSR͕؆୯ʹ࣮ݱͰ͖ Δ
• ॆ࣮ͨ͠υΩϡϝϯτ • https://jp.vuejs.org/ -
Nuxt.js Λ͏͜ͱͷϝϦοτ • SSRΛखܰʹVue.jsϕʔεͰ࣮Ͱ͖Δ • ΞϓϦέʔγϣϯ࣮ʹूதͰ͖ΔڥΛ؆୯ʹߏ ஙͰ͖Δ • ௨৴ͷ࠷దԽ •
ৄ͘͠ http://techblog.scouter.co.jp/entry/ 2017/11/13/120000 -
దԠϓϩδΣΫτͷ֓ཁ • ཧը໘Λ0͔Β࡞͢ΔϓϩδΣΫτ • ϑϩϯτΤϯδχΞ1໊ + αʔόʔαΠυ1໊ • UIϨΠΞτ <<<
ػೳੑ < ։ൃεϐʔυ • ࣾʹLaravel, Vue.jsͷݟཷ·͍ͬͯΔ -
ํͱಉҰϦϙͰཧ |-- app |-- artisan |-- bootstrap |-- composer.json |--
composer.lock |-- config |-- database |-- phpunit.xml |-- public |-- resources |-- routes |-- server.php |-- storage |-- tests |-- vendor |-- client |-- node_modules |-- nuxt.config.js |-- package.json `-- yarn.lock -
ํͱಉҰϦϙͰཧ |-- app |-- artisan |-- bootstrap |-- composer.json |--
composer.lock |-- config |-- database |-- phpunit.xml |-- public |-- resources |-- routes |-- server.php |-- storage |-- tests |-- vendor |-- client |-- node_modules |-- nuxt.config.js |-- package.json `-- yarn.lock client༻ͷϑΝΠ ϧҰՕॴʹ·ͱ ΊΔ -
/clientԼʹNuxtϓϩδΣΫτ client/ |-- assets |-- components |-- css |-- layouts
|-- middleware |-- mixins |-- pages |-- plugins |-- static |-- store `-- utils -
͜ͷߏͷͨΊʹΔ͜ͱ • ઃఆϑΝΠϧʹͯ client/ ΛಡΈʹߦ͘Α͏ʹઃఆ • LaravelʹσϑΥϧτͰఏڙ͞Ε͍ͯΔϑϩϯτؔ࿈ͷ ϑΝΠϧͷআ • Ϋϥαό௨৴ͷͨΊͷϞδϡʔϧՃ
• `nuxt generate`Ͱ੩తϑΝΠϧͷੜ • NginxͰ locationʹΑΔذ -
Ϋϥαό௨৴ͷͨΊͷϞδϡʔ ϧՃ yarn add @nuxtjs/axios module.exports = { srcDir: 'client/',
modules: [ '@nuxtjs/axios', ], axios: { } } nuxt.config.js -
NginxͰlocationʹΑΔذ server { location /api/ { root <σϓϩΠઌDir>/public/; index index.php;
try_files $uri $uri/ /api/index.php?$query_string; location ~ \.php$ { ... } } location / { alias <σϓϩΠઌDir>/dist/; index index.html; try_files $uri $uri/ /index.html = 404; } } -
NginxͰlocationʹΑΔذ server { location /api/ { root <σϓϩΠઌDir>/public/; index index.php;
try_files $uri $uri/ /api/index.php?$query_string; location ~ \.php$ { ... } } location / { alias <σϓϩΠઌDir>/dist/; index index.html; try_files $uri $uri/ /index.html = 404; } } /apiͷϦΫΤετ LaravelΛಡΈʹ ߦ͘ -
NginxͰlocationʹΑΔذ server { location /api/ { root <σϓϩΠઌDir>/public/; index index.php;
try_files $uri $uri/ /api/index.php?$query_string; location ~ \.php$ { ... } } location / { alias <σϓϩΠઌDir>/dist/; index index.html; try_files $uri $uri/ /index.html = 404; } } ͦΕҎ֎nuxt generate͞Εͨ ϑΝΠϧΛಡΈʹ ߦ͘ -
NginxͰlocationʹΑΔذ server { location /api/ { root <σϓϩΠઌDir>/public/; index index.php;
try_files $uri $uri/ /api/index.php?$query_string; location ~ \.php$ { ... } } location / { alias <σϓϩΠઌDir>/dist/; index index.html; try_files $uri $uri/ /index.html = 404; } } ϑΝΠϧΛಡΈʹ ߦͬͯଘࡏ͠ͳ͚ Ε/index.html ͰSPA -
αʔόʔ: Laravel Passport • Passport: LaravelެࣜఏڙͷOauth2ϓϥάΠϯ • Laravel5.5ͩͱcomposer install͢Δ͚ͩͰΤ ϯυϙΠϯτ͕ੜ͞ΕΔ
• ୯७ͳύεϫʔυೝূͰ͋ΕPasswordClient Ͱ -
ΫϥΠΞϯτ: @nuxtjs/auth ..? • ೝূʹඞཁͳػೳΛઃఆϑΝΠϧʹهड़͢Δ͚ͩͰ࣮ݱ • ϩάΠϯɺϩάΞτAPIͷϦΫΤετ • औಘͨ͠τʔΫϯͷӬଓԽ(Cookie, localStorage)
• ೝূɺඇೝূ࣌ͷϦμΠϨΫτmiddleware • nuxt_community͕ఏڙ • ͔͠͠ɺAPIͷํͰϩάΠϯϢʔβΛGET͢ΔΤϯυϙΠϯτ͕ଘࡏ͍ͯ͠Δඞཁ ͕͋ͬͨΓɺࡉ͔͍ڍಈʹ੍ؔͯ͠ޚ͕Ͱ͖ͳ͍ • ࠓճࣗ࡞ -
nuxt generateͱnuxtίϚϯυ ͷڍಈͷ͕͍ͪ • `nuxt`ίϚϯυͷ߹: • Ϗϧυ࣌ʹಡΈࠐΉϑΝΠϧશମʹbabelΛదԠͯ͘͠ΕΔɻ • `nuxt generate`ίϚϯυͷ߹:
• Nuxt.jsϓϩδΣΫτԼҎ֎ͷϑΝΠϧ(node_module)ͰES6ܗࣜͷ JSͩͱΤϥʔ • ίϯϙωϯτΛimport͢Δͱ͜ΖͰେจࣈͷϑΝΠϧ໊Λࢦఆ͠ɺ࣮ࡍͷ ϑΝΠϧ໊͕খจࣈͩͱΤϥʔ →`nuxt generate`ίϚϯυCIͰνΣοΫ -
1.0.0-rc3ͰͷมߋͱυΩϡϝ ϯτ • Aliases are now ~, ~~, @, @@,
assets and static (~plugins should be renamed to ~/ plugins for example) • Programmatic Usage is different now, see custom-server example and updated express template • build.loaders has been removed in nuxt.config.js, use build.extend instead • injectAs has been removed in plugins, you can inject your plugins by accessing app • process.BROWSER_BUILD has been removed in flavour of process.browser • process.SERVER_BUILD has been removed in flavour of process.server • Remove ~store and ~router aliases, use plugins to access router and store →1.0·ͰAPIมߋͳ͍͕ɺҰԠϦϦʔεϊʔτݟΑ͏ -
SSRͷͭΒΈ • SSRͰͷΈൃੜ͢ΔΤϥʔΛͨͲΔͷ͕େม(ϒϥβͷσϕϩούʔ πʔϧʹදࣔ͞Εͳ͍) • nuxt/youch(Nuxt७ਖ਼ΤϥʔϨϙʔςΟϯά)ͰΧόʔ͖͠Εͳ͍࣌ ͕͋Δ • 1.0ʹ্͕ΔλΠϛϯάͰSSRϞʔυͷOn OffબͰ͖ΔΑ͏ʹ
• ҰԠݱঢ়Ͱ`nuxt —spa`ͰΫϥΠΞϯτͷΈϏϧυՄೳ (> rc7 ) • process.mode = ‘spa’ͰspaϞʔυͰ࣮ߦՄೳ ( > rc7 ) →nuxt generate || <no-ssr/> || spaϞʔυ -
localStorage vs Cookie • Node.jsαʔόʔΛ༻͢Δ߹ localStorage༻ग़དྷͳ͍ͷͰɺCookieʹ σʔλΛอଘ͢Δඞཁ͕͋Δ import JsCookie from
'js-cookie' import Cookie from ‘cookie' … if (process.client) { window.localStorage.setItem('access_token', authData.access_token) JsCookie.set('access_token', authData.access_token) } else { this.$context.res.setHeader('Set-Cookie', Cookie.serialize('access_token', authData.access_token)) } -
Credential • CookieΛผυϝΠϯ͔ΒLaravelʹૹ৴͍ͨ͠߹ CORSͷઃఆ͕ඞཁ • barryvdh/laravel-cors Λ͏߹࠷ݶԼهͷΑ͏ʹઃ ఆ return [
- 'supportsCredentials' => false, - 'allowedOrigins' => ['*'], + 'supportsCredentials' => true, + 'allowedOrigins' => [ + env('APP_URL'), + ], 'allowedHeaders' => ['*'], 'allowedMethods' => ['*'], 'exposedHeaders' => [], 'maxAge' => 0, ]; -
·ͱΊ • Laravel + Nuxt.jsΛΔͳΒͪΐͬͱͨ͠Լ४ උΛ͠Α͏ • SSRΛલఏͱ͍ͯ͠ͳ͍αΠτͰLaravel + Nuxt.jsͰͷߏՄೳ
• ͨͩ͠ɺNuxt.jsͷόʔδϣϯʹҙ