Home > front end >  AWS setup resulting in CORS error with Elastic Beanstalk
AWS setup resulting in CORS error with Elastic Beanstalk

Time:04-24

I am working on my thesis about news recommendations and have been working on getting my web application running on AWS. My angular front-end runs on S3 with static hosting, my NodeJS back-end runs on Elastic Beanstalk along with my Flask API. The issue that I'm running into is that when I make a request from Node to Flask or even itself, I get a CROS Missing Allow Origin. I have therefore attempted to add these CORS headers, starting with access-control-allow-origin: * with GET, PUT, PATCH, PUT, DELETE, OPTIONS as methods. I have done this for both NodeJS as well as Flask, but the error remains unchanged. The site itself is available through enter image description here

enter image description here

NodeJS uses

app.use(express.json())

app.use((req, res, next) => {
  res.setHeader(
    "Access-Control-Allow-Origin",
    "*"
  );
  res.setHeader(
    "Access-Control-Allow-Headers",
    "Origin, X-Requested-With, Content-Type, Accept"
  );
  res.setHeader(
    "Access-Control-Allow-Methods",
    "GET, POST, PATCH, PUT, DELETE, OPTIONS"
  );

  next();
});

and Flask uses

import nltk
import numpy as np
from flask import Flask, request
from flask_restful import Api, Resource
from flask_cors import CORS, cross_origin
from nltk.sentiment import SentimentIntensityAnalyzer
from nltk.tokenize import word_tokenize
from sentence_transformers import SentenceTransformer

application = Flask(__name__)
CORS(application)
api = Api(application)

I would like to understand what exactly is causing this and how I could fix it. Thank you for your help

CodePudding user response:

After further debugging, it became clear that it was not actually a CORS error, but instead a server timeout. This was caused by an error that occurred when connecting to the database and was not picked up by the debugging code as part of the connection details that were supposed to be printed were in fact not properly configured on the server causing both the DB connection to fail as well as the debugging code that was supposed to log such a problem. Luckily it only took a week and a half to locate the problem :(

  • Related