as shown in the code posted below, for the front-end part, I invoking the webservice getTIFFForSubsetAsNIRRange/
and I want to send the contents shown in body
the webservice is invoked successfully but i can not get the body
posted to it.
As shown below in the back-end side, I used req.data
but it returns undefined
Please let me know how to have access to the contents sent to the backend
attempts to solve it
let data = req.body;
res.send('Data Received: ' + JSON.stringify(data));
but it results in an error:
UnhandledPromiseRejectionWarning: Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client
front-end:
drawEvt.on('drawend', e => {
let feature = e.feature;
let geom = feature.getGeometry();
let wktformat = new WKT();
let geoJSONformat = new GeoJSON();
let wktRepresenation = wktformat.writeGeometry(geom);
let geoJSONRepresentation = geoJSONformat.writeGeometry(geom);
this.wktRepresenation = wktRepresenation;
this.geoJSONRepresentation = geoJSONRepresentation;
console.info(debugTag, 'drawEvt.on' + 'wktRepresenation:', this.wktRepresenation);
console.info(debugTag, 'drawEvt.on' + 'geoJSONRepresentation:', this.geoJSONRepresentation);
const requestOptions = {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ wktRepresenation: this.wktRepresenation }),
,
};
fetch('http://localhost:4000/getTIFFForSubsetAsNIRRange/', requestOptions)
.then(response => response.json())
.then(data => (this.postId = data.id));
});
back-end
app.post('/getTIFFForSubsetAsNIRRange/', async (req, res, next) => {
console.log(res.send(req.body))
return 'OK'
});
app.listen(port, () => {
console.log('listening to port', port);
});