質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
Nuxt.js

Nuxt.jsは、ユニバーサルなSPAが開発可能なVue.jsベースのフレームワーク。UIの描画サポートに特化しており、SSRにおけるサーバーサイドとクライアントサイドのUIレンダリングなどさまざまな機能を持ちます。

Heroku

HerokuはHeroku社が開発と運営を行っているPaaSの名称です。RubyやNode.js、Python、そしてJVMベース(Java、Scala、Clojureなど)の複数のプログラミング言語をサポートしている。

Ruby on Rails

Ruby on Railsは、オープンソースのWebアプリケーションフレームワークです。「同じことを繰り返さない」というRailsの基本理念のもと、他のフレームワークより少ないコードで簡単に開発できるよう設計されています。

Q&A

0回答

290閲覧

HerokuでRails+Nuxtのアプリをデプロイしたい

Meitoku

総合スコア44

Nuxt.js

Nuxt.jsは、ユニバーサルなSPAが開発可能なVue.jsベースのフレームワーク。UIの描画サポートに特化しており、SSRにおけるサーバーサイドとクライアントサイドのUIレンダリングなどさまざまな機能を持ちます。

Heroku

HerokuはHeroku社が開発と運営を行っているPaaSの名称です。RubyやNode.js、Python、そしてJVMベース(Java、Scala、Clojureなど)の複数のプログラミング言語をサポートしている。

Ruby on Rails

Ruby on Railsは、オープンソースのWebアプリケーションフレームワークです。「同じことを繰り返さない」というRailsの基本理念のもと、他のフレームワークより少ないコードで簡単に開発できるよう設計されています。

0グッド

0クリップ

投稿2022/09/22 14:13

実現したいこと、発生している問題

Rails(APIモード)+Nuxt.jsで作成したアプリをHerokuにデプロイしたのですが、デプロイ済みのURLを開くと、添付画像のVue.jsのデフォルト画面が出てきて自分が作成した画面が出てこない。
正常にデプロイできるようにしたいです。よろしくお願いいたします。
イメージ説明

前提

こちらの方法を参考にして、プロジェクト内にbackフォルダとfrontフォルダを作成しました。backフォルダの中でrails newをし、frontフォルダの中でyarn create nuxt-appをして、
バックとフロントを分離しました。back配下でrails sを fornt配下でyarn devをしてアプリを起動させます。
Rails(ポート3000) Nuxt(ポート8080)

デプロイ方法

$heroku create アプリ名 $heroku config:set HOST=0.0.0.0 $heroku buildpacks:add --index 1 heroku/nodejs $git push heroku master

Herokuのログ

イメージ説明

該当のソースコード

関係がありそうなものを貼ります
package.json

json

1{ 2 "name": "front", 3 "version": "1.0.0", 4 "private": true, 5 "scripts": { 6 "dev": "nuxt", 7 "build": "nuxt build", 8 "start": "nuxt start", 9 "generate": "nuxt generate", 10 "postinstall": "npm run build" 11 }, 12 "dependencies": { 13 "@nuxtjs/axios": "^5.13.6", 14 "@nuxtjs/proxy": "^2.1.0", 15 "core-js": "^3.19.3", 16 "nuxt": "^2.15.8", 17 "vue": "^2.6.14", 18 "vue-server-renderer": "^2.6.14", 19 "vue-template-compiler": "^2.6.14", 20 "vuetify": "^2.6.1", 21 "webpack": "^4.46.0", 22 "@nuxtjs/vuetify": "^1.12.3" 23 }, 24 "devDependencies": { 25 } 26}

Procfileはローカルでのアプリの起動の仕方を記述しています

Procfile

1server: cd back && rails s 2web: cd front && yarn dev

back/config/puma.rb

ruby

1# Puma can serve each request in a thread from an internal thread pool. 2# The `threads` method setting takes two numbers: a minimum and maximum. 3# Any libraries that use thread pools should be configured to match 4# the maximum value specified for Puma. Default is set to 5 threads for minimum 5# and maximum; this matches the default thread size of Active Record. 6# 7max_threads_count = ENV.fetch("RAILS_MAX_THREADS") { 5 } 8min_threads_count = ENV.fetch("RAILS_MIN_THREADS") { max_threads_count } 9threads min_threads_count, max_threads_count 10 11# Specifies the `worker_timeout` threshold that Puma will use to wait before 12# terminating a worker in development environments. 13# 14worker_timeout 3600 if ENV.fetch("RAILS_ENV", "development") == "development" 15 16# Specifies the `port` that Puma will listen on to receive requests; default is 3000. 17# 18port ENV.fetch("PORT") { 3000 } 19 20# Specifies the `environment` that Puma will run in. 21# 22environment ENV.fetch("RAILS_ENV") { "development" } 23 24# Specifies the `pidfile` that Puma will use. 25pidfile ENV.fetch("PIDFILE") { "tmp/pids/server.pid" } 26 27# Specifies the number of `workers` to boot in clustered mode. 28# Workers are forked web server processes. If using threads and workers together 29# the concurrency of the application would be max `threads` * `workers`. 30# Workers do not work on JRuby or Windows (both of which do not support 31# processes). 32# 33# workers ENV.fetch("WEB_CONCURRENCY") { 2 } 34 35# Use the `preload_app!` method when specifying a `workers` number. 36# This directive tells Puma to first boot the application and load code 37# before forking the application. This takes advantage of Copy On Write 38# process behavior so workers use less memory. 39# 40# preload_app! 41 42# Allow puma to be restarted by `rails restart` command. 43plugin :tmp_restart

nuxt.config.js

js

1import colors from 'vuetify/es5/util/colors' 2 3export default { 4 5 server: { 6 port: 8080 7 }, 8 // Disable server-side rendering: https://go.nuxtjs.dev/ssr-mode 9 ssr: false, 10 11 // Global page headers: https://go.nuxtjs.dev/config-head 12 head: { 13 titleTemplate: '%s - front', 14 title: 'front', 15 htmlAttrs: { 16 lang: 'en' 17 }, 18 meta: [ 19 { charset: 'utf-8' }, 20 { name: 'viewport', content: 'width=device-width, initial-scale=1' }, 21 { hid: 'description', name: 'description', content: '' }, 22 { name: 'format-detection', content: 'telephone=no' } 23 ], 24 link: [ 25 { rel: 'icon', type: 'image/x-icon', href: '/favicon.ico' } 26 ] 27 }, 28 29 // Global CSS: https://go.nuxtjs.dev/config-css 30 css: [ 31 ], 32 33 // Plugins to run before rendering page: https://go.nuxtjs.dev/config-plugins 34 plugins: [ 35 ], 36 37 // Auto import components: https://go.nuxtjs.dev/config-components 38 components: true, 39 40 // Modules for dev and build (recommended): https://go.nuxtjs.dev/config-modules 41 buildModules: [ 42 // https://go.nuxtjs.dev/vuetify 43 '@nuxtjs/vuetify', 44 ], 45 46 // Modules: https://go.nuxtjs.dev/config-modules 47 modules: [ 48 '@nuxtjs/axios', 49 '@nuxtjs/proxy', 50 ], 51 proxy: { 52 '/api/': { 53 target: 'http://localhost:3000', 54 } 55 }, 56 axios: { proxy: true }, 57 58 // Vuetify module configuration: https://go.nuxtjs.dev/config-vuetify 59 vuetify: { 60 customVariables: ['~/assets/variables.scss'], 61 theme: { 62 dark: true, 63 themes: { 64 dark: { 65 primary: colors.blue.darken2, 66 accent: colors.grey.darken3, 67 secondary: colors.amber.darken3, 68 info: colors.teal.lighten1, 69 warning: colors.amber.base, 70 error: colors.deepOrange.accent4, 71 success: colors.green.accent3 72 } 73 } 74 } 75 }, 76 77 // Build Configuration: https://go.nuxtjs.dev/config-build 78 build: { 79 }, 80}

試した事

1つのdynoで動かす方法があったのでexpressを導入してみましたが、デプロイに失敗しました

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだ回答がついていません

会員登録して回答してみよう

アカウントをお持ちの方は

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問