this is my index.js backend on AWS Lambda I alredy tried CORS every sigle way we know but its still not work. T.T may I need to setting something in AWS first?
const { ApolloServer, gql } = require('apollo-server-lambda')
const express = require('express');
const cors = require('cors');
const jwt = require('express-jwt');
const cookieParser = require('cookie-parser');
const schema = require('./graphql');
const mongoose = require('mongoose');
const path = "/graphql";
const server = new ApolloServer({
schema,
context: ({ event, context }) => ({
headers: event.headers,
functionName: context.functionName,
event,
context,
})
});
exports.handler = server.createHandler({
expressGetMiddlewareOptions: {
cors: {
origin: "http://localhost:3000",
credentials: true,
}
},
expressAppFromMiddleware(middleware) {
const app = express();
const mongodb_uri = "mongodb+srv://###############################################"
mongoose.Promise = Promise;
mongoose.connect(mongodb_uri, {
dbName: "myDB",
promiseLibrary: Promise,
useNewUrlParser: true,
useUnifiedTopology: true,
useCreateIndex: true,
useFindAndModify: false,
});
app.use(cookieParser());
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(
cors({
origin: "http://localhost:3000",
credentials: true,
})
);
});
when I call backend from http://localhost:3000 (frontend) so we get error
Access to fetch at 'https://####################################' from origin 'http://localhost:3000' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: The value of the 'Access-Control-Allow-Origin' header in the response must not be the wildcard '*' when the request's credentials mode is 'include'.
createHttpLink.ts:145 POST https://#################################### net::ERR_FAILED