I have this endpoint on backend (node, express):
router.post('/createUser', (req, res, next) => {
try{
const { user } = req.body;
if(!user) next(createError(401))
data.push(user);
res.status(200).json(user)
} catch(e) {
next(e)
}
})
and this on front (service)
class EmployeeService {
constructor() {
this.api = axios.create({
baseURL: process.env.REACT_APP_BACK_DOMAIN || 'http://localhost:4000',
withCredentials: true
})
}
getPaginated = (page, size) => this.api.get(`/?page=${page}&size=${size}`).then(({data}) => data)
createUser = user => this.api.post('/createUser', user).then(({data}) => data)
}
When i receive createUser
Request, i take body from req, but it is undefined, i console log "req" and this returned me an incoming message object
Why? i need to receive body for push on array :(