Getting CORS error after adding Dockerfile to my Django project

72 views Asked by At

So to keep it brief, I have a fullstack application which is deployed on Railway. Everything worked perfectly. Then I decided to integrate celery so I can run some tasks in background.

Now in order to use celery in production I wanted to containerize my Django app where it can also run celery. So I followed some tutorials and added Dockerfile to my Django app.

Dockerfile:

FROM python:3.9.7

WORKDIR /app


COPY . /app


RUN pip install -r requirements.txt


ENV DJANGO_SETTINGS_MODULE=backend.settings
ENV CELERY_BROKER_URL=redis://default:***********************-43.railway.app:****


ARG RAILWAY_ENVIRONMENT

ENV PORT = 8080

EXPOSE 8080

CMD ["python", "-m", "celery", "-A", "backend", "worker", "--loglevel=info","--pool=solo"]

Everysince I added this, my application is facing this CORS issue..I dont know why and I searched thru google and I couldnt find any answers, I am new to Docker so I hope to get some insight on this.

[From client side][1]

Here is my CORS config in Django:

CORS_ALLOW_ALL_ORIGINS = False


CORS_ALLOWED_ORIGINS = [
    'http://localhost:3000',
    'https://checkout.stripe.com',
  
    
    'https://sendit-frontend-production.up.railway.app'
]

CORS_ALLOW_CREDENTIALS = True


MIDDLEWARE = [
    "corsheaders.middleware.CorsMiddleware",
    'django.middleware.security.SecurityMiddleware',

    'whitenoise.middleware.WhiteNoiseMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',

]
0

There are 0 answers