Я развернул приложение MERN на heroku. Я могу получить доступ к целевой странице и перемещаться по страницам, но когда я пытаюсь позвонить на маршруты API на сервере, приложение вылетает. Локально приложение работает отлично. проблема возникает в производстве.
это мой сервер. js файл:
const express = require("express");
const app = express();
const connectDB = require("./config/db");
const path = require("path");
// Connect DB
connectDB();
// Init Middleware
app.use(express.json({ extended: false }));
app.use("/api/auth", require("./routes/api/auth"));
app.use("/api/users", require("./routes/api/users"));
app.use("/api/clientes", require("./routes/api/clientes"));
app.use("/api/local", require("./routes/api/local"));
if (process.env.NODE_ENV === "production") {
app.use(express.static("client/usuarios/build"));
app.get("*", (req, res) => {
res.sendFile(
path.resolve(__dirname, "client", "usuarios", "build", "index.html")
);
});
}
const PORT = process.env.PORT || 5000;
app.listen(PORT, () => console.log(`Server started on port ${PORT}`));
А это пакет . json:
{
"name": "mercado",
"version": "1.0.0",
"description": "App de compras",
"main": "server.js",
"scripts": {
"start": "node server",
"server": "nodemon server",
"usuarios": "npm start --prefix client/usuarios",
"locales": "npm start --prefix client/locales",
"dev-usuarios": "concurrently \"npm run server\" \"npm run usuarios\"",
"heroku-postbuild": "NPM_CONFIG_PRODUCTION=false npm install --prefix client/usuarios && npm run build --prefix client/usuarios"
},
"dependencies": {
"aws-sdk": "^2.649.0",
"bcryptjs": "^2.4.3",
"config": "^3.3.1",
"cors": "^2.8.5",
"express": "^4.17.1",
"express-validator": "^6.4.0",
"jsonwebtoken": "^8.5.1",
"mongoose": "^5.9.7",
"multer": "^1.4.2",
"multer-s3": "^2.9.0"
},
"devDependencies": {
"concurrently": "^5.1.0",
"nodemon": "^2.0.2"
}
}
А это логи герою
2020-04-23T22:48:30.863113+00:00 heroku[web.1]: State changed from starting to up
2020-04-23T22:48:30.803402+00:00 app[web.1]: Server started on port 15776
2020-04-23T22:49:00.874382+00:00 app[web.1]: connection <monitor> to 52.205.15.208:27017 closed
2020-04-23T22:49:00.882434+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2020-04-23T22:49:00.882662+00:00 app[web.1]: npm ERR! errno 1
2020-04-23T22:49:00.883614+00:00 app[web.1]: npm ERR! mercado@1.0.0 start: `node server`
2020-04-23T22:49:00.883721+00:00 app[web.1]: npm ERR! Exit status 1
2020-04-23T22:49:00.883871+00:00 app[web.1]: npm ERR!
2020-04-23T22:49:00.883979+00:00 app[web.1]: npm ERR! Failed at the mercado@1.0.0 start script.
2020-04-23T22:49:00.884050+00:00 app[web.1]: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
2020-04-23T22:49:00.891636+00:00 app[web.1]:
2020-04-23T22:49:00.891892+00:00 app[web.1]: npm ERR! A complete log of this run can be found in:
2020-04-23T22:49:00.892035+00:00 app[web.1]: npm ERR! /app/.npm/_logs/2020-04-23T22_49_00_884Z-debug.log
2020-04-23T22:49:00.965661+00:00 heroku[web.1]: State changed from up to crashed