What causes the net::ERR CONNECTION REFUSED error?

FRIENDS! I need help. I can't determine what is causing the error net:: ERR_CONNECTION_REFUSED. The backend and frontend applications work fine, except for what concerns requests/CORS.

enter a description of the image here
enter a description of the image here


The code on the host is deployed, according to of this article. Naturally, I updated all the packages before putting them into production. On the host (VPS: CentOS7, VestaCP) installed nginx + php-fpm, and also MongoDB, node.js, @vue/cli. All the necessary ports are open:

enter a description of the image here


The server and client parts are located in the same directory/on the same domain. Here is the structure:

enter a description of the image here


All dependencies to work with packages are accounted for. Compilation of production and server startup is stable and error-free:

enter a description of the image here


What is most interesting, requests in browsers are cut, and through Postman I perfectly receive/send/update data:

enter a description of the image here

+++Code server.js+++

let express = require('express');
let app = express();
let bodyParser = require('body-parser');

// Parse requests
app.use(bodyParser.urlencoded({
  extended: true
}));
app.use(bodyParser.json());

// Load CORS
const cors = require('cors');
const corsOptions = {
  credentials: true,
  origin: 'http://localhost:4200',  // сменил на http://<имя моего домена>
  allowedHeaders: ['Content-Type'],
  optionsSuccessStatus: 200
};
app.use(cors(corsOptions));

// Configuring the database
const dbConfig = require('./app/config/mongodb.config.js');
const mongoose = require('mongoose');

mongoose.Promise = global.Promise;

// Connecting to the database
mongoose.connect(dbConfig.url, {
    useNewUrlParser: true,
    useFindAndModify: false
  })
  .then(() => {
    console.log("Successfully connected to MongoDB.");
  }).catch(err => {
    console.log('Could not connect to MongoDB.');
    process.exit();
  });

require('./app/routes/customer.routes.js')(app);

// Create a Server
let server = app.listen(dbConfig.serverport, () => {

  let host = server.address().address;
  let port = server.address().port;

  console.log("App listening at http://%s:%s", host, port)
});

+++Code mongodb.config.js+++

module.exports = {
  url: 'mongodb://<имя юзера>:<пароль>@localhost:27017/<имя бд>',
  serverport: 8080   // сменил на свободный порт 8081
};

+++Code http-common.js+++

import axios from 'axios'

export default axios.create({
  baseURL: "http://localhost:8080/api",  // сменил на свободный порт 8081
  headers: {
    "Content-type": "application/json",
  }
});

Waiting for your suggestions or maybe even a SOLUTION.


1 answers

Error found. Everything was decided:

  • replacing the origin option on the server (CORS): from localhost:4200 to http: / /.
  • port reconfiguration: listening port 8080 was open, but busy with another process. I set up a different listening port on the server and repeated it on the client.

Everything worked. Thank you all!..

 1
Author: Алексей Малинков, 2019-06-19 11:17:58