1

I have this problem:

Access to XMLHttpRequest at 'https://blabla.execute-api.blabla.amazonaws.com/prod/sondage/croisement/test/' from origin 'https://master.test.amplifyapp.com' has been blocked by CORS policy: Request header field content-type is not allowed by Access-Control-Allow-Headers in preflight response.

pour commencer du tout voici ma configuration:

  • server Fastapi qui run sur un ec2
  • un amplify (avec un front en vuejs)
  • un api gateway

At first I just wanted to have my front and my back but the front didn't accept requests on an http server so I used api gateway to resolve this.

What's strange is that my login party doesn't have any problems.auth service

but on my dashboard service I can't make a POST request (but GET requests work)dashboard service

Here is the configuration for the Cors in my Backend

origins = [
"https://master.test.amplifyapp.com/",
"https://master.test.amplifyapp.com",
"https://master.test.amplifyapp.com/*",
"https://master.test2.amplifyapp.com",
"https://master.test2.amplifyapp.com/*",
]
app.add_middleware(
CORSMiddleware,
allow_origins=origins,
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*", "Content-Type"],
max_age=3600
)

this and example of my posts router


app.include_router(authentication.router,
    prefix="/authentication",
                       tags=["authentication"])
app.include_router(sondage.router,
                       prefix="/sondage",
                       tags=["sondage"])


@router.post("/ppt/{name}/", status_code=status.HTTP_201_CREATED)
async def generate_ppt(name: str, param: FilterModel, session: SessionLocal = Depends(get_session),
                          current_user: UserAdminOut = Depends(get_current_user)):

    ad = session.query(Ad).filter(Ad.name == name).first()

    if ad is None:
        return responses.Response(status_code=status.HTTP_404_NOT_FOUND, content=f"Ad {name} pas trouvé")

    dynamic_quiz = session.query(DynamicQuiz).filter(DynamicQuiz.ad_id == ad.id).first()

    if dynamic_quiz is None:
        return responses.Response(status_code=status.HTTP_404_NOT_FOUND, content=f"quizz pour {name} pas trouvé")
    sondages, all_responses = get_all_dynamic_quiz(dynamic_quiz, session)
    ppt = GeneratePpt(enquetes=sondages, all_responses=all_responses, filter = param, title_of_ppt=name.replace(" ", ""), title_of_dir=name.replace(" ", ""), session=session)
    ppt.execute()
    return responses.Response(status_code=status.HTTP_201_CREATED)

i want to say my api gateway is fonctionnal because i test it with postman so it's just my front is not working (i think)

as you can see from my cors configuration, I've put in several urls but it still doesn't work. I've also tried modifying the routes on my backend but to no avail.`

Chris
  • 18,724
  • 6
  • 46
  • 80

0 Answers0