Programming WebRTC: How to configure CORS for the signaling server

@karlstolley

I want to run the signaling server and the front-end (e.g., basic_p2p app) on separate ports.

From the client side, I get this “CORS missing allow origin” when connecting to the server.
How to solve that issue?

What I tried so far (and that didn’t work):

// server.js
const cors = require("cors");
const app = express();
app.use(cors());

Hi Huynh!

There’s a couple of ways to handle this. One would be to worry about CORS only on the socket server. Have a look at Socket.io docs at Handling CORS | Socket.IO

Or, to continue your method of working directly with Express, have a close look at their documentation, including Express cors middleware

If you’re not yet skilled with using a tool like curl, that will help you determine the headers coming back from both your app and signaling servers, and help you figure out where additional adjustments or configuration is needed.