Closed louwjlabuschagne closed 11 months ago
Do you know that express
requires body-parser
to parse the body of requests?
Sorted thanks!
If anyone in future needs the express code to POC a server:
const express = require("express");
const app = express();
var bodyParser = require("body-parser");
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());
app.post("/locations", (req, res) => {
console.log("/locations was called");
const { body } = req;
const { headers } = req;
console.log({ headers });
console.log(JSON.stringify(body, null, 2));
res.send({ success: true });
res.status(200);
});
// catch all other routes
app.get("*", (req, res) => {
console.log("404 - Not Found");
res.send("404 - Not Found");
});
app.listen(3000, () => console.log("Server running on port 3000"));
Issue Description
We are attempting to post location data to a custom server hosted locally using Express, but we are encountering an issue where the body of the POST request is empty. We have configured the app accordingly in a React Native environment with the following setup:
Problem
While the POST requests are being received by the server, the body of these requests is empty. We suspect that there may be a dependency on the
/register
endpoint that the package in the app requires to allow the body to be transmitted successfully.Request for Clarification
/register
endpoint that we need to implement for successful transmission of the request body?/register
endpoint to allow the transmission of location data in the request body?Additional Information
:3000
.console
locally does work and receives the POSTs from the simulatorAny assistance or guidance on resolving this issue would be greatly appreciated. Thank you!