geckosio / geckos.io

🦎 Real-time client/server communication over UDP using WebRTC and Node.js http://geckos.io
BSD 3-Clause "New" or "Revised" License
1.35k stars 85 forks source link

CORS Issue ? #274

Closed Pi-Bouf closed 6 months ago

Pi-Bouf commented 11 months ago

Describe the bug Hello ! Since some weeks I try to make the example works and use it on another project. But still remain the same issue:

image

It's always un fucking CORS issue. Everything is pretty simple:

The snapshot-interpolation example is working on my Windows (WSL) computer, but now i'm on mac m2 and impossible to make it works.

Server.js

import express from 'express';
import geckos from '@geckos.io/server';
import http from 'http';

const app = express();
const server = http.createServer(app);
const io = geckos({ cors: {
    origin: '*',
    allowAuthorization: true,
} });

io.addServer(server);
io.onConnection(channel => {
    console.log('CONNECTION !');

    channel.onDisconnect(() => {
        console.log(`${channel.id} got disconnected`);
    });

    channel.on('chat message', data => {
        console.log(`got ${data} from "chat message"`);
        // emit the "chat message" data to all channels in the same room
        io.room(channel.roomId).emit('chat message', data);
    });
});

server.listen(3000, () => {
    console.log('Starting !');
});

app.get('/test', (req, res) => {
    res.send('Test route OK');
});

On CORS options, I tried everything, evem to set false on the allow flag and 'localhost' etc on the origin

Client.js


const channel = geckos({
    port: 3000,
});

channel.onConnect(error => {
    if (error) {
        console.error(error.message);
        return;
    }

    channel.on('chat message', data => {
        console.log(`You got the message ${data}`);
    });

    channel.emit('chat message', 'a short message sent to the server');
});

Have a question? Is it working on M2 ? (I saw datachannel not prebuilt on m2).

Pi-Bouf commented 6 months ago

No idea ?