Hello, I’m trying to show my deployed react SPA http://geotab-addin.netlify.app/ on the website https://my.geotab.com/metislab/#addin-wizard_setup-geotab-addin_netlify_app
In the beginning, I was getting CORS issues, but I managed to solve them by adding the following code in my netlify.toml file:
[build]
functions = “functions”
[[redirects]]
from = “/*”
to = “/index.html”
status = 200
[[headers]]
for = “/"
[headers.values]
Access-Control-Allow-Origin = "”
I have also created a netlify function with the following code:
let HEADERS = {
“Access-Control-Allow-Headers”:
“Origin, X-Requested-With, Content-Type, Accept, Access-Control-Allow-Origin”,
“Content-Type”: “application/json”, //optional
“Access-Control-Allow-Methods”: “POST, OPTIONS”,
“Access-Control-Max-Age”: “8640”,
};
//This solves the “No ‘Access-Control-Allow-Origin’ header is present on the requested resource.”
HEADERS[“Access-Control-Allow-Origin”] = “*”;
HEADERS[“Vary”] = “Origin”;
exports.handler = async function (event, context) {
try {
if (event.httpMethod === “OPTIONS”) {
return { statusCode: “204”, HEADERS };
}
if (event.httpMethod === “POST”) {
const body = JSON.parse(event.body);
//Your code goes here
return {
statusCode: 200,
body: "Success",
HEADERS,
};
}
return {
statusCode: 401,
HEADERS,
};
} catch (e) {
console.error(e);
return {
statusCode: 500,
body: e.toString(),
};
}
};
However, when I try to see my app on the Geotab website, I just get a blank page. I’ve checked the consoles and no errors at all.
The last 2 entries show me a code 204, but I don’t know if the issue is because of this and how to solve it.
I’m stuck at this right now, so I cannot put it in production properly, and any help will be appreciated.
I’ve been using the command “netlify deploy” to upload this and it is connected to Github.