WaspW
Wasp13mo ago
mgp25

CORS Issue

Wasp version: 0.13.2
Backend: https://api.mydomain.com

I have read other issues regarding CORS and I have deployed everything as the documentation recommends:

I have a serverSetup.ts file which has the following:

import cors from 'cors'
import { config, type MiddlewareConfigFn } from 'wasp/server'

export const serverMiddlewareFn: MiddlewareConfigFn = (middlewareConfig) => {
  // Example of adding an extra domains to CORS.
  middlewareConfig.set('cors', cors({ origin: [config.frontendUrl, 'https://mydomain.com'] }))
  return middlewareConfig
}


As far as I know config.frontendUrl should be already https://mydomain.com but I have added since I am not able to get it working.

In main.wasp I have added the following:

  wasp: {
    version: "^0.13.2"
  },
  server: {
    middlewareConfigFn: import { serverMiddlewareFn } from "@src/serverSetup"
  },


But I am still getting on client:

[Error] XMLHttpRequest cannot load https://api.mydomain.com/auth/me due to access control checks.
[Error] Failed to load resource: Origin https://mydomain.com is not allowed by Access-Control-Allow-Origin. Status code: 404 (me, line 0)


NGINX config:

    location / {
        proxy_pass http://localhost:3001;  # Forward requests to the backend server
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_cache_bypass $http_upgrade;
    }


Any idea what I am missing?
Was this page helpful?