0
[SOLUTION]
It was necessary for me to configure the Postman Authorization tab and select the Type Bearer Token option and pass the token
When trying to access a route in my API using the POST method Postman said that the server did not send any reply.
Then I decided to remove Header Authorization which contains my token and then he accessed the route and returned the response:
Here’s a snippet of the server code where I import the routes:
app.use(cors());// <--- Pacote para habilitar CORS
app.use(express.static('public'));
app.use(bodyParser.json());
app.use('/auth', authRoutes);
app.use('/user', userRoutes);// <--- Ele segue por essa rota
And this is the middleware responsible for the route:
router.post('/posts', isAuth, (req, res, next) => {//O isAuth não interfere em nada. Eu já o removi e o comportamento continua o mesmo
res.status(201).json({
success: true,
message: 'Foi'
})
})
module.exports = router;
Why can’t I access this route using Header Authorization?
I’m using the Expressjs framework
I find it interesting to post what the
isAuth
doing it. By the description it doesn’t seem to be far from it.– Leo Cavalcante
Could you pass the type of post you’re doing? Depending on the type of post, your body pass might be set wrong. BP Docs: https://www.npmjs.com/package/body-parser Medium story: https://medium.com/@febatista107/how-to-convert-the-data of a-request-with-o-body-parser-2b5b93100f00
– Ryan Lucas
@Leocavalcante I purposely omit this so as not to create confusion because it would take the focus of the problem. I tested with and without isAuth and the result was the same.
– Sidiney Silva
Ryan Lucas I edited the post pointing out what the problem was
– Sidiney Silva