A
A
Adel Khalitov2019-02-19 20:56:48
Angular
Adel Khalitov, 2019-02-19 20:56:48

Why is nodejs not accepting requests from angular on different ports?

Good afternoon, my node does not accept requests from a client running on a different port.
I installed the headers on the node, angular does not swear:

app.use(function (req, res) {
  res.setHeader('Access-Control-Allow-Origin', '*');
  res.setHeader('Access-Control-Allow-Methods', 'GET, POST, OPTIONS, PUT, PATCH, DELETE');
  res.setHeader('Access-Control-Allow-Headers', 'X-Requested-With,content-type');
  res.setHeader('Access-Control-Allow-Credentials', true);
});
app.use('http://localhost:3000/', router);


router.get('http://localhost:3000/getLeadList', function(req, res) {
    console.log('Пришел запрос');
    db.Lead.find({}).then(function(leads) {
        console.log(leads);
        res.send(leads);
    });
});

But nothing happens, and the request does not reach the server.

I don't know why it doesn't work?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Adel Khalitov, 2019-02-19
@SaveLolliPoP

It was enough to install cors on nodejs
Here is the link

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question