Go/React: Safari Fetch API cannot load due to access control checks

Viewed 103

I've been trying to resolve this CORS problem for days now. I've tried several alternatives, including several variations to the server settings and using Axios to make the request. As far as I can tell, it's a problem with my server settings, but I can't identify what.

Here are the server settings:

func main() {
    router := gin.Default()
    router.Use(cors.New(cors.Config{
        AllowOrigins:     []string{"https://<location>.netlify.app", "https://<location>.netlify.app/admin"},
        AllowMethods:     []string{"GET", "POST", "OPTIONS"},
        AllowHeaders:     []string{"Origin"},
        AllowCredentials: false,
        AllowOriginFunc: func(origin string) bool {
            return origin == "*"
        },
    }))

    router.GET("/patients", getPatients)
    router.Run("localhost:8080")
}

Here are the React settings:

/* Server Exports */
export const ENDPOINT = "http://localhost:8080";

export default function DataTable() {
    // Fetch data
    const fetcher = (url) =>
        fetch(`${ENDPOINT}/${url}`).then((res) => res.json());

    const { data } = useSWR("patients", fetcher);
...

Everything seems to work fine via Chrome/Chromium, but not Safari or Chrome on mobile.

Edit: Additional relevant info.. I am hosting on netlify and using react-router-dom. It works on localhost in Safari, but not deployed on netlify.

0 Answers
Related