transistorsoft / background-geolocation-console

A field-testing & analysis server for the Background Geolocation plugin
MIT License
151 stars 157 forks source link

Unable to Transmit Location Data to Custom Server via POST Request #135

Closed louwjlabuschagne closed 11 months ago

louwjlabuschagne commented 11 months ago

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:

// Configuration snippet
await BackgroundGeolocation.ready({
  url: 'http://192.168.110.251:3000/locations',
  method: 'POST',
  params: {
    user_id: '123',
    device_id: '123',
  },
  headers: {
    'X-FOO': 'BARR',
  },
  // Other configurations...
});

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

  1. Is there a specific dependency on the /register endpoint that we need to implement for successful transmission of the request body?
  2. If so, could you provide guidance on how we can implement the necessary configuration or modification to the /register endpoint to allow the transmission of location data in the request body?

Additional Information

Any assistance or guidance on resolving this issue would be greatly appreciated. Thank you!

christocracy commented 11 months ago

Do you know that express requires body-parser to parse the body of requests?

louwjlabuschagne commented 11 months ago

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"));