Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

Question Enabling CORs on Unity multiplay servers.

Discussion in 'Game Server Hosting' started by Brunosly, May 23, 2023.

  1. Brunosly

    Brunosly

    Joined:
    Nov 8, 2012
    Posts:
    6
    Hello!

    I have a WEBGL project where I use Unity Multiplay API'S to allocate servers. The problem is that my API response is getting blocked by CORs.
    I disabled CORs on my browser and it worked fine, how can I setup custom headers on the Unity multiplay servers?
     
  2. CMaster_Thomas

    CMaster_Thomas

    Joined:
    Jan 13, 2020
    Posts:
    5
    Bump, having same issue
     
  3. justaddice83

    justaddice83

    Joined:
    Sep 19, 2012
    Posts:
    45
    We're also having this issue.

    Running the WebGL on localhost is fine at communicating with Game Server Hosting (Multiplay) REST API. However when we upload to a host providor we get an CORS restriction error in the browser console:

    Access to fetch at 'https://services.api.unity.com/multiplay/servers/v1/projects/***/environments/***/servers' from origin 'https://ourdomain.com' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.


    The htaccess file:
    <IfModule mod_headers.c>
    Header add Access-Control-Allow-Origin "https://services.api.unity.com"
    Header add Access-Control-Allow-Credentials "true"
    Header add Access-Control-Allow-Headers "authorization, origin, user-token, x-requested-with, content-type"
    Header add Access-Control-Allow-Methods "PUT, GET, POST, DELETE, OPTIONS"
    Header merge Vary Origin
    </IfModule>
    AddType application/wasm .wasm


    The 'servers' API request:
    upload_2023-12-28_11-42-54.png

    And response:

    upload_2023-12-28_11-45-11.png

    Help would be very much appretiated.
     
  4. ThirdPartition

    ThirdPartition

    Joined:
    Mar 5, 2019
    Posts:
    5
    I'm also running into this issue!