Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

393
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!