heroku错误:ENOENT,stat'/app/build/index.html'

时间:2022-10-12 20:56:21

Im trying to deploy to heroku but Im getting Error: ENOENT, stat '/app/build/index.html' when I go to my address. Otherwise the application deployment does not give me any error. Can somebody explain what Im doing wrong. Here is my code and code structure.

我试图部署到heroku但我得到错误:ENOENT,stat'/app/build/index.html'当我去我的地址。否则,应用程序部署不会给我任何错误。有人可以解释我做错了什么。这是我的代码和代码结构。

server.js

var express = require('express'),
    server = express(),
    bodyParser = require('body-parser'),
    logger = require('morgan'),
    methodOverride = require('method-override'); // for heroku

var port = process.env.PORT || 5000;

server.use(express.static(__dirname + '/build'));
server.use('/src', express.static(__dirname + '/build/src'));       // js
server.use('/assets', express.static(__dirname + '/build/assets')); // css, images
server.use('/vendor', express.static(__dirname + '/build/vendor')); // other

server.use(logger('dev'));

server.get('/', function(req, res, next) {
  res.sendfile('index.html', { root: __dirname + '/build' });
});

server.listen(port, function() {
  console.log("Listening on " + port);
});

Structure in app

应用程序中的结构

├── Gruntfile.js
├── LICENSE
├── Procfile
├── README.md
├── bower.json
├── build
│   └── ....
├── build.config.js
├── config
│   └── db.js
├── karma
│   └── karma-unit.tpl.js
├── module.prefix
├── module.suffix
├── node_modules
│   └── ...
├── package.json
├── server.js
├── src
│   ├── app
│   ├── assets
│   ├── common
│   ├── index.html
│   └── less
└── vendor

Structure in app/build

app / build中的结构

├── assets
│   ├── O-viu-0.0.1.css
│   └── README.md
├── index.html
├── karma-unit.js
├── src
│   └── app
│       ├── about
│       │   └── about.js
│       ├── app.js
│       └── home
│           └── home.js
├── templates-app.js
├── templates-common.js
└── vendor
    ├── angular
    │   └── angular.js
    ├── angular-bootstrap
    │   └── ui-bootstrap-tpls.min.js
    ├── angular-ui-router
    │   └── release
    │       └── angular-ui-router.js
    └── placeholders
        └── angular-placeholders-0.0.1-SNAPSHOT.min.js

2 个解决方案

#1


6  

Figured it out. It was my .gitignore file where I included the /build folder.

弄清楚了。这是我的.gitignore文件,其中包含/ build文件夹。

#2


0  

Try somthing like this:

尝试这样的事情:

res.sendfile( __dirname + '/build/index.html' );

#1


6  

Figured it out. It was my .gitignore file where I included the /build folder.

弄清楚了。这是我的.gitignore文件,其中包含/ build文件夹。

#2


0  

Try somthing like this:

尝试这样的事情:

res.sendfile( __dirname + '/build/index.html' );