我在让我的 React /rails 应用程序在 heroku 上运行时遇到问题。我已经成功部署它并且 Rails 服务器启动,但我没有看到我的 React 应用程序。我觉得我已经很接近了,但不知道还缺少什么。
所以我的进程当前正在运行npm run build
从客户端目录本地构建一个“build”目录。然后我提交构建结果并推送到 Herokugit push heroku master
.
然后,我在浏览器中导航到 heroku 应用程序,在那里我只得到一个空白的白色页面,它是我手动从构建目录复制到公共的索引文件。我不确定索引文件是否正确,但我只是想确保我可以命中某些内容。
最终,我想推送存储库,它会自动运行构建。我已经在不同的地方看到过这个提到,但是当我运行时我总是收到一个反应脚本不存在的错误npm run build
在服务器上。
我的配置如下:
应用程序的基本结构
/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"
}
Procfile
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