Помогите пожалуйста, что не так? :5173/#header:1 Access to fetch at 'http://192.168.1.112:4000/graph...
Помогите пожалуйста, что не так?
:5173/#header:1 Access to fetch at 'http://192.168.1.112:4000/graphql' from origin 'http://192.168.1.112:5173' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.
Main.page.tsx:8
POST http://192.168.1.112:4000/graphql net::ERR_FAILED
server.ts:
import express, {Request, Response} from "express";
import config from 'config';
import ConnectToMongo from './utils/db.util';
import { graphqlHTTP } from 'express-graphql';
import { mainRootValue } from './resolvers/main.resolvers';
import { mainSchema } from './schema/main.schema';
import cors from 'cors';
import corsMiddleware from './middleware/cors.middleware';
ConnectToMongo();
const app = express();
app.use(cors({
origin: '*', // твой клиент
credentials: true, // если ты передаешь JWT / cookies
methods: ["GET", "HEAD", "PATCH", "POST", "DELETE", "OPTIONS"],
allowedHeaders: ["Origin", "X-Requested-With", "Content-Type", "Accept", "Authorization"]
}));
app.options("/graphql", cors())