问题
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