question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

has been blocked by CORS policy

See original GitHub issue

First of all I have been trying to solve this on my own but I have obviously not been able to.

Well I have the following:

Frontend error:

Screenshot_1

Backend Screenshot_2

import cors from "cors";
import http from "http";
import express from "express";
import path from 'path'

const port = 8080
const app = express();
const server = http.createServer(app);

app.use(cors());
app.use(express.json())
app.use(express.urlencoded({ extended: true }));

const main = async () => {
  // import geckos as ESM
  const { geckos } = await import('@geckos.io/server')
  const io = geckos({
      cors: { 
          origin: 'https://mywebsite.zyx',
          allowAuthorization: true,
        }
    })

  io.addServer(server)
  io.onConnection(channel => {
    console.log("New connection", channel.id)
    channel.onDisconnect(() => {
      console.log(`${channel.id} got disconnected`)
    })
   channel.emit(   "hello", "hello frontend");
    } catch (error) {
      console.log(error)
    }
    })
  })
  server.listen(port, () => {
    console.log(`Example app listening at http://localhost:${port}`)
  })
}
main()

Nginx

Screenshot_3

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:14 (8 by maintainers)

github_iconTop GitHub Comments

2reactions
yandeucommented, Jun 11, 2022

You’re welcome. Fix will be available in the next version.

1reaction
yandeucommented, Jun 11, 2022

Cool. I will improve to code (in the block below) to allow sub-paths like your /mysocket.

https://github.com/geckosio/geckos.io/blob/f0be95f669e7965afee39eef89c202733a743425/packages/server/src/httpServer/httpServer.ts#L29

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to solve 'Redirect has been blocked by CORS policy
1.We have to allow CORS, placing Access-Control-Allow-Origin: in header of request may not work. Install a google extension which enables a CORS ...
Read more >
Getting rid of “origin has been blocked by CORS” issue during ...
My application was running in localhost:8080 and dev server in some 10.10.1.123:80 (Hey you hackers, don't start something fishy as soon as you ......
Read more >
Access to XMLHttpRequest has been blocked by CORS policy ...
How to fix “Access to XMLHttpRequest has been blocked by CORS policy” in Chrome · 2.1 The 'Access-Control-Allow-Origin' header contains multiple values, but...
Read more >
Access to fetch been blocked by CORS policy - React Native + ...
This issue relate the 'no-cors' mode. Try to remove it. Access to fetch at 'https://localhost:40011/api/Games/GamesList' from origin 'http:// ...
Read more >
Fixing Common Problems with CORS and JavaScript
The message says that the browser has blocked the request because of a CORS policy. It suggests two solutions. The second suggestion is...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found