我在让我的 react /rails 应用程序在 heroku 上工作时遇到问题。我已经成功部署了它,并且 rails 服务器启动了,但是我没有看到我的 react 应用程序。我觉得我很接近,但无法弄清楚缺少什么。
所以我的流程目前是npm run build
从客户端目录本地运行,该目录在客户端中构建一个“构建”目录。然后我提交构建结果并使用git push heroku master
.
然后我在浏览器中导航到 heroku 应用程序,在那里我只得到一个空白页,这是一个索引文件,我手动从构建目录复制到公共。我不确定索引文件是否正确,但我只是想确保我能打到什么。
最终,我只想推送 repo,它会自动运行构建。我在各个地方都看到过这个,但是当我npm run build
在服务器上运行时,我总是得到一个 react-script does not exist 错误。
我的配置如下:
应用程序的基本结构
/app - root of Rails app
/client - root of React app
/public - does display index page
根/客户端/package.json
{
"name": "qc_react",
"version": "0.1.0",
"private": true,
"devDependencies": {
"react-scripts": "^0.8.4"
},
"dependencies": {
"react": "^15.4.1",
"react-dom": "^15.4.1",
"react-router": "^3.0.0"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test --env=jsdom",
"eject": "react-scripts eject"
},
"cacheDirectories": [
"node_modules",
"client/node_modules"
],
"proxy": "${API_URL}:${PORT}/v1/"
}
根/package.json
{
"name": "web",
"version": "1.0.0",
"description": "This repo contains a web application codebase. Read instructions on how to install.",
"main": "index.js",
"scripts": {
"build": "cd client" # not sure what to put here but this gets me past build failure
},
"repository": {
"type": "git",
"url": "git+ssh://myrepo.git"
},
"author": "",
"license": "ISC",
"homepage": "https://myhomepage#readme"
}
档案
api: bundle exec puma -C config/puma.rb
构建包
1. https://github.com/mars/create-react-app-buildpack.git
2. heroku/ruby
配置/puma.rb
workers Integer(ENV['WEB_CONCURRENCY'] || 2)
threads_count = Integer(ENV['RAILS_MAX_THREADS'] || 5)
threads threads_count, threads_count
preload_app!
rackup DefaultRackup
port ENV['PORT'] || 3001
environment ENV['RACK_ENV'] || 'development'
on_worker_boot do
# Worker specific setup for Rails 4.1+
# See: https://devcenter.heroku.com/articles/deploying-rails-applications-with-the-puma-web-server#on-worker-boot
ActiveRecord::Base.establish_connection
end