Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

394
Visualizações
CORS not working on AWS Lambda (expressAppFromMiddleware)

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
over 4 years ago · Santiago Trujillo
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda