0
I made a CRUD with Nodejs, Express, Handlebars and Mongodb - Works great in development, but when I try to make the Deploy in Heroku from the continuous error "Cannot GET /".
I’ve researched a lot of materials that actually report problems, but I haven’t been able to fix them yet.
Can you help me ?
Follow my config:
app.js
// Models
const express = require('express')
const handlebars = require('express-handlebars')
const app = express()
const admin = require('./routes/admin')
const path = require('path')
const mongoose = require('mongoose')
const session = require('express-session')
const flash = require('connect-flash')
const dotenv = require('dotenv')
dotenv.config()
const mongoURI = process.env.mongoURI
// Express
app.use(express.urlencoded({
extended: true
}))
app.use(express.json())
// Mongoose
mongoose.Promise = global.Promise
mongoose.connect(mongoURI, {
useNewUrlParser: true,
useCreateIndex: true,
useUnifiedTopology: true,
useFindAndModify: false
}).then(() => {
console.log("Conectado com sucessoao MongoDB!")
}).catch((err) => {
console.log("Erro ao se conectar ao MongoDB: " + err)
})
// Public
app.use(express.static(path.join(__dirname, 'public')))
// Routes
app.use('/admin', admin)
// Others
const PORT = process.env.PORT || 8081
app.listen(PORT, () => {
console.log("Servidor rodando!")
})
package.json:
{
"name": "cadastro_cli",
"version": "1.0.0",
"main": "app.js",
"dependencies": {
"connect-flash": "^0.1.1", "dotenv": "^10.0.0", "express": "^4.17.1", "express-handlebars": "^5.3.2", "express-session": "^1.17.2", "handlebars": "^4.7.7", "mongoose": "^5.13.3", "nodemon": "^2.0.12", "path": "^0.12.7"
}
,
"devDependencies": {
"nodemon": "^2.0.12"
}
,
"scripts": {
"start": "node app.js"
}
,
"engines": {
"node": "13.14.0", "npm": "6.14.4"
}
,
"author": "@alexcamposwd",
"license": "MIT",
"description": ""
}