Socket io CORS 错误无法通过 Socket.io 将客户端连接到 Nodejs 服务器

Socket io CORS error Can't Connect Client To Nodejs Server Through Socket.io

我有工作的 Nodejs 服务器,我到达 localhost:4000(工作正常)。我正在尝试通过 socketio 将客户端连接到 Nodejs 之外的服务器。从 localhost:8888/page(MAMP 应用程序)到套接字,但我在控制台中得到 ERR_FAILED 200。有一些东西阻止连接到套接字。

Node.js server.js:

import fetch from 'node-fetch';
import express from 'express';
const app = express();
import http from 'http';
const server = http.createServer(app);
import {Server} from 'socket.io';
const io = new Server(server);
import mysql from 'mysql';

{...}

server.listen('4000', () => {
  console.log("Server running on port 4000");
});

节点应用程序之外的网页:

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title></title>
  <script src="https://cdn.socket.io/4.4.1/socket.io.min.js" integrity="sha384-fKnu0iswBIqkjxrhQCTZ7qlLHOFEgNkRmK2vaO/LbTZSXdJfAu6ewRBdwHPhBo/H" crossorigin="anonymous">
  </script>
  </script>
</head>
<body>

<script src="http://localhost:4000/socket.io/socket.io.js"></script>
<script>

const socket = io.connect('http://localhost:4000/');


</script>
</body>
</html>

请帮忙..

https://socket.io/docs/v3/handling-cors/

const io = require("socket.io")(httpServer, {
  cors: {
    origin: "https://example.com",
    methods: ["GET", "POST"]
  }
});