Приложение MERN получает ошибку соединения в digitalocean - PullRequest
0 голосов
/ 29 апреля 2020

Я создал Blog, используя приложение MERN. Так что теперь я размещаю это на digitalocean сервере, но я получаю ECONNREFUSED ошибку. Я следил за большей частью документа как на YouTube, так и на других сайтах для его размещения.

Я вижу, что мой клиент работает на ex: http://154.23.54.44:3000, но он не работает без :3000, а также не подключен ни мой mlab conection.

Любые предложения по решению этой проблемы и запуску этого приложения в реальном производстве. Большое спасибо.

// пакет сервера. json

"main": "server.js",
  "scripts": {
    "client-install": "npm install --prefix client",
    "start": "node server.js",
    "server": "nodemon server.js",
    "client": "npm start --prefix client",
    "dev": "concurrently \"npm run server\" \" npm run client\"",
    "heroku-postbuild": "NPM_CONFIG_PRODUCTION=false npm install --prefix client && npm run build --prefix client"
  }

// сервер. js

const express = require('express');
const mongoose = require('mongoose');

const path = require('path');
const config =  require('config');

const app = express();

//bodyParser middleware
app.use(express.json());

//DB config
const db = config.get('mongoURI');

//connect to mongo
mongoose
.connect(db, {useNewUrlParser: true, useUnifiedTopology: true, useCreateIndex: true})
.then(() => console.log('MongoDB connected...'))
.catch(err => console.log(err));

//use routes
app.use('/api/users', require('./routes/api/users'));
app.use('/api/auth', require('./routes/api/auth'));


// Serve static assets if in production
if(process.env.NODE_ENV === 'production') {
    // SET static folder
    app.use(express.static('client/build'));
    app.get('*', (req, res) => {
        res.sendFile(path.resolve(__dirname, 'client', 'build', 'index.html'));
    });
}

const port = process.env.PORT || 80;

app.listen(port, () => console.log(`Server started on PORT ${port}`));

// клиент (пакет. json)

{
  "name": "client",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "@testing-library/jest-dom": "^4.2.4",
    "@testing-library/react": "^9.3.2",
    "@testing-library/user-event": "^7.1.2",
    "axios": "^0.19.2",
    "bootstrap": "^4.4.1",
    "bootstrap-less": "^3.3.8",
    "moment": "^2.24.0",
    "node-sass": "^4.13.1",
    "react": "^16.13.1",
    "react-dom": "^16.13.1"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject"
  },
  "eslintConfig": {
    "extends": "react-app"
  },
  "browserslist": {
    "production": [
      ">0.2%",
      "not dead",
      "not op_mini all"
    ],
    "development": [
      "last 1 chrome version",
      "last 1 firefox version",
      "last 1 safari version"
    ]
  },
  "proxy": "http://localhost:5000"
}

// ошибка на производстве

enter image description here

...