0

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',

]
4
  • Add the container's name that is sending the request to the CORS_ALLOWED_ORIGINS list. Commented Oct 19, 2023 at 14:25
  • I still get the same error, the way I placed it is like this: 'reverent_easley', So just the name of the container, but it doesnt work. Commented Oct 19, 2023 at 14:56
  • I hope you didn't forget to add 'corsheaders' in INSTALLED_APPS. So probably you additional need update\create CORS_ALLOW_HEADERS Commented Oct 20, 2023 at 6:35
  • Hey! No I didnt of course, like I mentioned in post, everything was working fine up until I added Dockerfile with those instructions you see up there..so I am not sure what is the cause of that issue still.. Commented Oct 20, 2023 at 6:38

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.