O
O
Orc2019-06-19 08:32:37
CORS
Orc, 2019-06-19 08:32:37

What causes the net::ERR_CONNECTION_REFUSED error?

Good time, friends!
Need help. Can't determine what is causing the net::ERR_CONNECTION_REFUSED error .
Backend and frontend applications work fine, except for requests/CORS.
5d09bb2058571748195728.png
5d09de80a382b938800152.png
>>>>
The code on the host is deployed, according to this article . Naturally, I updated all packages before being released to production.
The host ( VPS : CentOS7 , VestaCP ) has nginx + php-fpm installed , as well as MongoDB , node.js , @vue/cli . Ports open:
5d09de263a57f592843867.png
>>>>
The server and client parts are located in the same directory/on the same domain. Here is the structure:
5d09bbcd15b47222899410.png
>>>>
All dependencies for the packages to work are taken into account. Compiling production and running the server is stable and without errors:
5d09c2f9756c4247012627.png
>>>>
What is most interesting, requests in browsers are cut, and I can receive / send / update data perfectly through Postman:
5d09c5e079f76654076039.png
>>>>

server.js code

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)
});


mongodb.config.js code

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


http-common.js code

import axios from 'axios'

export default axios.create({
  baseURL: "http://localhost:8080/api",
  headers: {
    "Content-type": "application/json",
  }
});


I'm waiting for your suggestions or maybe even a DECISION .

Answer the question

In order to leave comments, you need to log in

1 answer(s)
O
Orc, 2019-06-19
@z0ddak

Error found. Everything was decided:
-
1 . by replacing the origin option on the server (CORS): from localhost:4200 to http://<my domain> .
2 . port reconfiguration: Listening port 8080 was open, but occupied by another process. Set a different port to listen on the server and retry it on the client.
-
Everything worked. Thanks to all...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question