franciscop / server

:desktop_computer: Simple and powerful server for Node.js
https://serverjs.io/
MIT License
3.56k stars 170 forks source link

Added "cors" to list of socket options #156

Open grrbm opened 1 month ago

grrbm commented 1 month ago

We need to be able to pass cors options to the socket.io instance:

server(
  {
    port,
    socket: {
      cors: {
        origin: "http://localhost:3000",
        methods: ["GET", "POST"],
        allowedHeaders: ["Content-Type"],
        credentials: true,
      },
    },
  },
  cors,
  [
    get("/", (ctx) => render("index.html")),
    socket("connect", updateCounter),
    socket("disconnect", updateCounter),
    socket("message", sendMessage),
  ]
);