has been blocked by CORS policy
See original GitHub issueFirst 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:
Backend
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
Issue Analytics
- State:
- Created a year ago
- Comments:14 (8 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
You’re welcome. Fix will be available in the next version.
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