Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CORS issue with Next.js and countly-sdk-web #82

Closed
JacquesLeupin opened this issue Oct 27, 2020 · 1 comment
Closed

CORS issue with Next.js and countly-sdk-web #82

JacquesLeupin opened this issue Oct 27, 2020 · 1 comment

Comments

@JacquesLeupin
Copy link

JacquesLeupin commented Oct 27, 2020

I'm getting the following CORS issue when attempting to run the countly-sdk-web with Next.js. The error I receive is:

Access to XMLHttpRequest at 'https://countly.doc.ai/i?begin_session=1&metrics=%7B%22_app_version%22%3A%220.0%22%2C%22_ua%22%3A%22Mozilla%2F5.0%20(Macintosh%3B%20Intel%20Mac%20OS%20X%2010_15_7)%20AppleWebKit%2F537.36%20(KHTML%2C%20like%20Gecko)%20Chrome%2F86.0.4240.111%20Safari%2F537.36%22%2C%22_resolution%22%3A%222560x1440%22%2C%22_density%22%3A2%2C%22_locale%22%3A%22en-US%22%7D&app_key=ad952f815d0d64be3fa7c5a39692e7833959e449&device_id=60997e91-16a7-4981-a907-d50e1700b34d&sdk_name=javascript_native_web&sdk_version=20.04&timestamp=1603830178200&hour=13&dow=2' from origin 'http://localhost:9000' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.

Here is the script I'm running in my _app.jsx:

        <script
          type="text/javascript"
          dangerouslySetInnerHTML={{
            __html: `
            Countly.init({
              // provide your app key that you retrieved from Countly dashboard
                  app_key: {app_key_here},
              
              // Provide your server IP or name. Use try.count.ly or us-try.count.ly 
              // or asia-try.count.ly for EE trial server.
              // If you use your own server, make sure you have https enabled if you use
              // https below.  
                  url: {url}
                  
                });
                // track sessions automatically
                Countly.track_sessions();
                // track pageviews automatically
                Countly.track_pageview();
        `,
          }}
        />

I've tried enabling https://expressjs.com/en/resources/middleware/cors.html middleware in my Next.js app, but I still receive the same error.

Any chance my setup is incorrect?

Thanks for looking into this.

@ar2rsawseen
Copy link
Member

Hello,
I think this is problem on Countly server, not your server
please make sure you have Access-Control-Allow-Origin: * or other origin control setup in
Countly dashboard -> top cog -> Configurations -> Security -> Additional API HTTP Response headers

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants