Answer the question
In order to leave comments, you need to log in
How to make automatic POST request to front api?
On expressJS, you need to do authorization if you have a token. If there is a token in the cookie, you need to make a POST request to api ... The question is, how can this be done? That is, the presence of a token in cookies is checked when the page is reloaded, and the user is searched for by the token and authorized.
Answer the question
In order to leave comments, you need to log in
for express there is node-fetch
we
check the cookie through cookie_parser and if it is correct, then we just call and make a request
if (req.cookies.mySuperCookie === 'valid') {
const apiResults = await fetch('./api/mySuperApi', {method: 'post'} )
.....
return ..
}
const baseUrl = req ? `${req.protocol}://${req.get('Host')}` : '';
const response = await fetch(baseUrl + '/posts');
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question