I’m trying to deploy my app to Heroku, it runs fine locally. I’m getting the error in the logs after the build:
heroku[router]: at=info method=GET path="/" host=appname.herokuapp.com fwd="xx.xxx.xxx.xxx" dyno=web.1 connect=0ms service=8ms status=404 bytes=415 protocol=https
When trying to view the app I get the cannot GET / error, I’ve looked through a bunch of similar errors & can’t find where I’m going wrong.my app.js file is located at ./server/app.js
app.js
const express = require("express");
const http = require("http");
var cors = require("cors");
const morgan = require("morgan");
const bodyParser = require("body-parser");
const path = require("path");
const mongoose = require("mongoose");
const createError = require("http-errors");
const { Router } = require("express");
let codeRoutes = require("./api/code-routes.js");
/**
* App configurations
*/
let app = express();
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.use(morgan("dev"));
app.use(cors());
app.use(express.static(path.join(__dirname, "../dist/my-app")));
app.use(
"/",
express.static(path.join(__dirname, "../dist/my-app"))
);
/**
* Variables
*/
const MONGODB_URI =
"myMongoDBConnString";
/**
* Database connection
*/
mongoose
.connect(MONGODB_URI, {
promiseLibrary: require("bluebird"),
useUnifiedTopology: true,
useNewUrlParser: true,
})
.then(() => {
console.debug(`Connection to the database instance was successful`);
})
.catch((err) => {
console.log(`MongoDB Error: ${err.message}`);
}); // end mongoose connection
app.use("/api", myApi);
app.listen(process.env.PORT || 3000, function () {
console.log("Application is running at localhost:" + app.get("port"));
});
package.json
{
"name": "myapp",
"version": "0.0.0",
"scripts": {
"ng": "ng",
"start": "node ./server/app.js",
"server": "nodemon ./server/app.js",
"build": "ng build",
"watch": "ng build --watch --configuration development",
"test": "ng test",
"localhost": "ng build && node ./server/app.js"
},