I have this in Server 1:
try {
const res = await axios.post('https://subdomain.example.com/get-data', { data: ['Hi from example.com'] }, { headers: {'content-type': 'text/json'} });
console.log('post done');
} catch(err) {
console.log(err);
}
And in Server 2 it hits this route:
app.use(bodyParser.urlencoded({ extended: false, limit: '500mb' }));
app.use(bodyParser.json({limit: '500mb'}));
app.use(express.json({limit: '500mb'}));
app.use(cookieParser());
var corsOptions = {
origin: 'https://www.example.com',
optionsSuccessStatus: 200 // For legacy browser support
}
app.post("/get-data", (req, res) => {
console.log('get-data hit');
console.log(req.body) // returns undefined
return res.json({ success: true });
});
The console.log('get-data hit');
is shown in Server 2 but:
The issue is the req.body
is undefined
!
How can I get the { data: ['Hi from example.com'] }
in server 2?