Проблемы с развертыванием приложения стека MERN - PullRequest
0 голосов
/ 13 февраля 2020

Я не могу развернуть мое приложение с полным стеком.

Мой репозиторий выглядит точно так же с точки зрения структуры папок:

Ниже приведен мой пакет. json: https://github.com/bradtraversy/mern_shopping_list

{
  "name": "clear",
  "version": "1.0.0",
  "description": "",
  "main": "server.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "start:prod": "NODE_ENV=production nodemon server.js",
    "debug": "ndb server.js",
    "server": "nodemon server.js",
    "client": "cd client && npm start",    
    "build": "cd client && npm run build",    
    "dev": "concurrently --kill-others-on-fail \"npm run server\" \"npm run client\"",
    "start": "node server.js",
    "heroku-postbuild": "cd client && npm install && npm install --only=dev --no-shrinkwrap && npm run build"    
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "bcryptjs": "^2.4.3",
    "body-parser": "^1.19.0",
    "compression": "^1.7.4",
    "concurrently": "^5.1.0",
    "cookie-parser": "^1.4.4",
    "cors": "^2.8.5",
    "dotenv": "^8.1.0",
    "express": "^4.17.1",
    "express-mongo-sanitize": "^1.3.2",
    "express-rate-limit": "^5.0.0",
    "helmet": "^3.21.1",
    "hpp": "^0.2.2",
    "html-to-text": "^5.1.1",
    "jsonwebtoken": "^8.5.1",
    "mongoose": "^5.7.1",
    "morgan": "^1.9.1",
    "multer": "^1.4.2",
    "ndb": "^1.1.5",
    "nodemailer": "^6.3.0",
    "path": "^0.12.7",
    "pug": "^2.0.4",
    "slugify": "^1.3.5",
    "stripe": "^7.9.1",
    "validator": "^11.1.0",
    "xss-clean": "^0.1.1"
  },
  "engines": {
    "node": "^10"
  }
}

1 Ответ

1 голос
/ 13 февраля 2020

Можете ли вы попробовать это-

Это сервер. js содержимое файла: -

const express = require("express");
const path = require("path");
const app = express();
require("dotenv").config();
app.use(express.static(path.join(__dirname, "build")));

app.get("/", function(req, res) {
  res.sendFile(path.join(__dirname, "build", "index.html"));
});

app.get("/*", function(req, res) {
  res.sendFile(path.join(__dirname, "build", "index.html"));
});

app.listen(process.env.PORT || 3000);

Это часть моего скрипта: -

  "scripts": {
    "start:production": "npm install && npm run build && npm run start:prod",
    "start:prod": "cross-env NODE_ENV=production node server",
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject"
  },

Команда запуска в производство: -

npm run start:production
...