Heroku can't find server.js

余生颓废 提交于 2020-01-06 05:58:24

问题


I'm having problems figuring out why Heroku can't find my server.js file under the 'app' folder which is where it's looking for it. I have followed the following steps more than once: 1. Deleted the existing .git folder and the existing Heroku respository. I then init a new git respository and created a new Heroku respository and push to Heroku. Here are my docs:

server.js

const express = require('express');
const app = express();
const path = require('path');

app.use(express.static(__dirname + '/dist'));

app.listen(process.env.PORT || 3000);

/*
PathLocationStrategy - lets Angular handle routing for sub-routes instead of the server.
 When we type in some sub-route of our application, index.html will get served
 before any other route that might get typed into the address bar.  Angular will handle any sub-routes.
*/

app.get('/*', function(req, res) {
  res.sendFile(path.join(__dirname + '/dist/index.html'));
});

console.log('Console listening on port 3000');

Here is an image of my file structure showing server.js:

Here is the Heroku log:

https://gist.github.com/c9991932e7adc3bb6298f1228482fa02.git

Any help would be greatly appreciated. Thanks in advance.


回答1:


What does your Procfile file look like?

It should be something like:

web: node ./src/app/server

and once you do that I think your paths will be wrong for your resources. If your index.html file is in dist/schoolsdropdown then

 __dirname + '/dist/index.html

would be:

__dirname + '../../dist/schoolsdropdown/index.html


来源:https://stackoverflow.com/questions/50821680/heroku-cant-find-server-js

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!