#"GET /static/graphene_django/graphiql.js HTTP/1.1" 404

17 messages · Page 1 of 1 (latest)

arctic lintel
#
import os
import dotenv
from django.conf import settings

dotenv.load_dotenv()

# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent

# Define the MEDIA_ROOT and MEDIA_URL
MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')

# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/5.0/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = os.environ['U_SECRET_KEY']

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = os.environ['U_ALLOWED_HOSTS'].split(',')

# Application definition

INSTALLED_APPS = [
    'graphene_django',
    'user_management.apps.UserManagementConfig',
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'corsheaders',
]

CORS_ALLOWED_ORIGINS = os.environ['U_CORS_ALLOWED_ORIGINS'].split(',')
#
MIDDLEWARE = [
    'django.middleware.security.SecurityMiddleware',
    'whitenoise.middleware.WhiteNoiseMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'corsheaders.middleware.CorsMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'

ROOT_URLCONF = 'users.urls'

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
            ],
        },
    },
]

WSGI_APPLICATION = 'users.wsgi.application'

# Database configuration using environment variables
DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql',
        'NAME': os.environ['U_DB_NAME'],
        'USER': os.environ['U_DB_USER'],
        'PASSWORD': os.environ['U_DB_PASSWORD'],
        'HOST': os.environ['U_DB_HOST'],
        'PORT': '5432',
    }
}
#
# Password validation
# https://docs.djangoproject.com/en/5.0/ref/settings/#auth-password-validators

AUTH_PASSWORD_VALIDATORS = [
    {
        'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
    },
]

# Internationalization
# https://docs.djangoproject.com/en/5.0/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_TZ = True

# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/5.0/howto/static-files/

STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'static/')  # Directory for collected static files

# Default primary key field type
# https://docs.djangoproject.com/en/5.0/ref/settings/#default-auto-field

DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'

GRAPHENE = {
    "SCHEMA": "users.schema.schema"
}

GRAPHQL_ENDPOINT = "http://localhost:8001/graphql"

# Access to the cookie is restricted to the server alone
SESSION_COOKIE_HTTPONLY = True

LOGGING = {
    'version': 1,
    'disable_existing_loggers': False,
    'handlers': {
        'console': {
            'level': 'DEBUG',
            'class': 'logging.StreamHandler',
        },
    },
    'loggers': {
        '': {
            'handlers': ['console'],
            'level': 'DEBUG',
        },
    },
}
#

i am using docker to run all services and here is my users dockerfile as well:

#
FROM python:3.10

# Set environment variables
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1

ARG DATABASE_HOST
ARG DATABASE_NAME
ARG DATABASE_USER
ARG DATABASE_PASSWORD

# Set the working directory in the container
WORKDIR /code

# Copy the dependencies file to the working directory
COPY requirements.txt /code/

# Install dependencies
RUN pip install -r requirements.txt

RUN apt-get update
RUN apt-get upgrade -y
RUN apt-get install postgresql-client -y

COPY . /code/

CMD until pg_isready -h ${DATABASE_HOST} -U ${DATABASE_USER} -p 5432 ; \
do >&2 echo "Users Database is not ready - waiting..." ;\
sleep 2 ;\
done ; \
 \
>&2 echo "Users Database is ready." && \
export PGPASSWORD="${DATABASE_PASSWORD}" && \
if ! psql -h ${DATABASE_HOST} -p 5432 -U ${DATABASE_USER} -lqt | cut -d \| -f 1 | grep -qw ${DATABASE_NAME}; then \
    echo "Creating database ${DATABASE_NAME}..." && \
    psql -h ${DATABASE_HOST} -p 5432 -U ${DATABASE_USER} -c "CREATE DATABASE ${DATABASE_NAME}"; \
fi && \
echo "Applying migrations" && \
python3 manage.py makemigrations && \
python3 manage.py migrate && \
echo "Starting Kafka consumers" && \
set -m && \
python3 manage.py start_kafka_consumers & \
echo "Starting collecting static files" && \
python3.10 manage.py collectstatic --noinput & \
echo "Starting Django server" && \
python3.10 manage.py runserver 0.0.0.0:8000
#

when i run the service container i get a dir called static created in the main dir of the django project with all the static files this is after the running of the collectstatic command in the dockerfile

#

and i get 200 as response from graphql but the static file look like missing

#
[09/Aug/2024 10:55:05] "GET /static/graphene_django/graphiql.js HTTP/1.1" 404 1894
[09/Aug/2024 10:55:05] "GET /graphql HTTP/1.1" 200 2611
[09/Aug/2024 10:55:05] "GET /static/graphene_django/graphiql.js HTTP/1.1" 404 1894
gloomy sedge
#

"runserver" doesn't serve static files unless DEBUG is set to True

#

you either need to add something like "whitenoise" to your INSTALLED_APPS, or use a reverse proxy like nginx that handles them

#

ah I see you are using whitenoise

#

if you've got your code on github, and if it's super-easy for me to just clone it, and run it, and see what you're seeing, I'll give that a try and see if I can figure something out

arctic lintel
#

for whitenoise it does not really do anything, i just added lately to fix the issue but it does make no diff

gloomy sedge
#

well it should; maybe you've got it subtly misconfigured somehow

#

that's why I'm willing to clone your project and poke around

arctic lintel
#

ok just when you clone it change the branch to "backend", and one more thing when you ran make be ready to take some time cause i have to download a bunch of dependencies