So basically I've got a MEVN-stack app hosted on Heroku and I've been struggling for days trying to understand why my Axios posts won't work on Android but are O.K on P.C. The only time I got it to work was when I hardcoded the IP while debugging locally but since I can't have a static I.P in Heroku that won't work. I've even tried to dynamically change the BaseURL to the I.P-address in production without any luck. Is there anything I'm missing completely? I've read about "usesCleartextTraffic" for android and some issues regarding both headers and certificates. I'm deep down the rabbit hole and nothing seems to work.
I'll provide snippets through the stack for the request;
From the view:
import GuestsService from "../services/GuestsService.js";
async registerGuestMail() {
await GuestsService.registerGuestMail({ email: this.email })
.then(
response => (
(this.apiResponse =
"Request O.K")
)
)
.catch(
err => (
console.log(err),
(this.apiResponse = "Request failed")
)
);
From GuestService.js:
import axios from 'axios'
export default {
registerGuestMail(params) {
return axios.post('registerGuestMail', params)
}
}
In app.js - express:
const express = require('express')
const bodyParser = require('body-parser')
const cors = require('cors')
const morgan = require('morgan')
const mongoose = require('mongoose');
const app = express()
app.use(morgan('combined'))
app.use(bodyParser.json())
app.use(cors())
mongoose.connect(" - insert connection string here - ")
app.post('/registerGuestMail', userController.signupPost);
app.listen(process.env.PORT || 8081, process.env.IP)
As stated before, it works, deployed in Heroku, but only for P.C (if I set the baseURL: to 'http://localhost:8081')