CORS error when using fetch() in JavaScript

The issue has finally been fixed, thank you so much @WindLother and @dragonhunter1 for your help! :grinning:

(Full code below if needed:)

index.js

const express = require("express");
const app = express();
const http = require("http");
const sockets = require("socket.io");
const cors = require("cors");

app.use(cors({
  origin: "https://tic-tac-toe-ultimate.snakebyte.repl.co",
  methods: "GET",
  preflightContinue: false,
  optionsSuccessStatus: 204,
  credentials: true
}));

app.use(express.static("public"));

const server = http.createServer(app);

const io = sockets(server, {
  cors: {
    origin: "https://tic-tac-toe-ultimate.snakebyte.repl.co",
    methods: ["GET", "POST"],
  },
});

app.get("/api/connection-check", (req, res) => {
  res.json({
    server_status: "good",
  });
});

const port = process.env.PORT || 3000;
server.listen(port, function () {
  console.log("Listening on port", port);
});
1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.