I'm trying to implement this little login system of mine, and I have a form that sends a post request to my webpack dev server, which in turn proxies the request to my server.
This is the function that handles the form submit and sends a POST request to the server.
handleSubmit = (e) => {
e.preventDefault();
this.props.form.validateFields((err, values) => {
if (!err) {
console.log('Received values of form: ', values);
fetch('/login', {
method: 'POST',
body: values
});
}
});
}
When I click Login, I do get my values logged in the console as shown here http://prntscr.com/hsbpyp
This is the server side code which handles the login endpoint
const app = express();
app.use(bodyParser.urlencoded({ extended: false }));
app.post('/login', (req, res) => {
console.log('Got user information: \n', req.body);
res.send('asd');
})
app.use('/graphql', bodyParser.json(), graphqlExpress({ schema }));
app.use('/graphiql', graphiqlExpress({ endpointURL: '/graphql' }));
app.listen(3001, () => {
console.log(`
=====
Server running at http://localhost:3001/
GraphiQL running at http://localhost:3001/graphiql/
=====
`)
})
As you can see, I'm indeed using the body-parser middleware to parse the req.body but when I attempt to log the body, I get an empty object http://prntscr.com/hsbqrd
Can someone help me figure out what is going on with my code?