I have an Angular 5 App.
This is what I have in my package.json
{
"name": "web",
"version": "0.0.0&
Correct your code in Server.js
const express = require('express');
const app = express();
const path = require('path');
app.use(express.static(__dirname+'/dist'));
app.listen(process.env.PORT||8080);
//Path Location Strategy
app.get('/', function(req, res) {
res.sendFile(path.join(__dirname+'/dist/index.html'));
});
console.log('Console Listening');
For future reference -
try running logs command before hitting the URL.
$ heroku logs
Then check the logs for further details.
Usually when this error happens to me I have problems with node dependencies. Try to remove the node_modules folder, and the dist folder. From there spin everything up again, this mimics how heroku will build your project.
I suggest for more simplicity, if you want to deploy the backend on heroku as api and the he front end on github and activate cross origin resource sharing on browsing computer, I am actually building such app, that is my plan otherwise if you get any good news of this way your are doing update me
In your server.js you need to redirect your http call to the index.
app.route('/*', function(req,res) {
res.redirect(__dirname + '/dist/index.html')
})
In the above it'll redirect any call to your index.html.
Try adding @angular-devkit/build-optimizer as a package in the package.json file.
"dependencies": {
"@angular-devkit/build-optimizer": "^0.4.0",
...
}
This allows the post-install flag --aot to run. For some reason this package isn't built in anymore.
Here's how I make my Angular app to deploy and work on Heroku:
server.js should look something like this: https://hastebin.com/zavehahide.jspackage.json, move @angular/cli and @angular/compiler-cli from devDependencies to dependenciespackage.json, add postinstall: ng build --prod and start: node server.js to scriptsYou should be good to go.