From 74e862cd72d66ac92f2fff399e17759f731b5955 Mon Sep 17 00:00:00 2001 From: Anirudh Prabhakaran Date: Sun, 30 Jul 2023 19:46:35 +0530 Subject: [PATCH 1/2] Added logging to both backend and frontend --- backend/corpus/middleware.py | 12 ++ backend/corpus/settings.py | 281 ++++++++++++++++++----------------- backend/requirements.txt | 20 +-- backend/start.sh | 2 +- docker-compose.yml | 160 ++++++++++---------- frontend/package-lock.json | 186 +++++++++++++++++++++-- frontend/package.json | 3 + frontend/src/hooks.server.ts | 17 +++ nginx/Dockerfile | 10 +- nginx/default.conf | 3 + 10 files changed, 454 insertions(+), 240 deletions(-) create mode 100644 backend/corpus/middleware.py create mode 100644 frontend/src/hooks.server.ts diff --git a/backend/corpus/middleware.py b/backend/corpus/middleware.py new file mode 100644 index 00000000..056f8896 --- /dev/null +++ b/backend/corpus/middleware.py @@ -0,0 +1,12 @@ +import logging + + +class RequestLoggerMiddleware: + def __init__(self, get_response): + self.get_response = get_response + self.logger = logging.getLogger(__name__) + + def __call__(self, request): + self.logger.info(request.__dict__) + response = self.get_response(request) + return response diff --git a/backend/corpus/settings.py b/backend/corpus/settings.py index 463daf49..93d1101c 100644 --- a/backend/corpus/settings.py +++ b/backend/corpus/settings.py @@ -1,134 +1,147 @@ -""" -Django settings for corpus project. - -Generated by 'django-admin startproject' using Django 4.2.2. - -For more information on this file, see -https://docs.djangoproject.com/en/4.2/topics/settings/ - -For the full list of settings and their values, see -https://docs.djangoproject.com/en/4.2/ref/settings/ -""" -import os -from pathlib import Path - -# Build paths inside the project like this: BASE_DIR / 'subdir'. -BASE_DIR = Path(__file__).resolve().parent.parent - - -# Quick-start development settings - unsuitable for production -# See https://docs.djangoproject.com/en/4.2/howto/deployment/checklist/ - -# SECURITY WARNING: keep the secret key used in production secret! -SECRET_KEY = os.environ["SECRET_KEY"] - -# SECURITY WARNING: don't run with debug turned on in production! -DEBUG = os.environ["ENVIRONMENT"] == "DEVELOPMENT" - -ALLOWED_HOSTS = ["localhost", "127.0.0.1"] -if os.environ["ENVIRONMENT"] == "PRODUCTION": - ALLOWED_HOSTS.append("ieee.nitk.ac.in") - - -# Application definition - -INSTALLED_APPS = [ - "django.contrib.admin", - "django.contrib.auth", - "django.contrib.contenttypes", - "django.contrib.sessions", - "django.contrib.messages", - "django.contrib.staticfiles", - "rest_framework", -] - -MIDDLEWARE = [ - "django.middleware.security.SecurityMiddleware", - "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", -] - -ROOT_URLCONF = "corpus.base_url" - -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 = "corpus.wsgi.application" - - -# Database -# https://docs.djangoproject.com/en/4.2/ref/settings/#databases - -DATABASES = { - "default": { - "ENGINE": "django.db.backends.postgresql", - "NAME": os.environ["POSTGRES_DB"], - "USER": os.environ["POSTGRES_USER"], - "PASSWORD": os.environ["POSTGRES_PASSWORD"], - "HOST": os.environ["POSTGRES_HOST"], - "PORT": os.environ["POSTGRES_PORT"], - } -} - - -# Password validation -# https://docs.djangoproject.com/en/4.2/ref/settings/#auth-password-validators - -AUTH_PASSWORD_VALIDATORS = [ - { - "NAME": "django.contrib.auth.password_validation.UserAttributeSimilarityValidator", # noqa: E501 - }, - { - "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/4.2/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/4.2/howto/static-files/ - -if not DEBUG: - STATIC_URL = "static/" - STATIC_ROOT = os.path.join(BASE_DIR, "static") -else: - STATIC_URL = "/api/static/" - -# Default primary key field type -# https://docs.djangoproject.com/en/4.2/ref/settings/#default-auto-field - -DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField" +""" +Django settings for corpus project. + +Generated by 'django-admin startproject' using Django 4.2.2. + +For more information on this file, see +https://docs.djangoproject.com/en/4.2/topics/settings/ + +For the full list of settings and their values, see +https://docs.djangoproject.com/en/4.2/ref/settings/ +""" +import os +from pathlib import Path + +# Build paths inside the project like this: BASE_DIR / 'subdir'. +BASE_DIR = Path(__file__).resolve().parent.parent + + +# Quick-start development settings - unsuitable for production +# See https://docs.djangoproject.com/en/4.2/howto/deployment/checklist/ + +# SECURITY WARNING: keep the secret key used in production secret! +SECRET_KEY = os.environ["SECRET_KEY"] + +# SECURITY WARNING: don't run with debug turned on in production! +DEBUG = os.environ["ENVIRONMENT"] == "DEVELOPMENT" + +ALLOWED_HOSTS = ["localhost", "127.0.0.1"] +if os.environ["ENVIRONMENT"] == "PRODUCTION": + ALLOWED_HOSTS.append("ieee.nitk.ac.in") + + +# Application definition + +INSTALLED_APPS = [ + "django.contrib.admin", + "django.contrib.auth", + "django.contrib.contenttypes", + "django.contrib.sessions", + "django.contrib.messages", + "django.contrib.staticfiles", + "rest_framework", +] + +MIDDLEWARE = [ + "django.middleware.security.SecurityMiddleware", + "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", + "corpus.middleware.RequestLoggerMiddleware", +] + +ROOT_URLCONF = "corpus.base_url" + +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 = "corpus.wsgi.application" + + +# Database +# https://docs.djangoproject.com/en/4.2/ref/settings/#databases + +DATABASES = { + "default": { + "ENGINE": "django.db.backends.postgresql", + "NAME": os.environ["POSTGRES_DB"], + "USER": os.environ["POSTGRES_USER"], + "PASSWORD": os.environ["POSTGRES_PASSWORD"], + "HOST": os.environ["POSTGRES_HOST"], + "PORT": os.environ["POSTGRES_PORT"], + } +} + +# Logging +LOGGING = { + "version": 1, + "disable_existing_loggers": False, + "handlers": { + "console": { + "class": "logging.StreamHandler", + }, + }, + "root": { + "handlers": ["console"], + "level": "DEBUG", + }, +} + + +# Password validation +# https://docs.djangoproject.com/en/4.2/ref/settings/#auth-password-validators + +AUTH_PASSWORD_VALIDATORS = [ + { + "NAME": "django.contrib.auth.password_validation.UserAttributeSimilarityValidator", # noqa: E501 + }, + { + "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/4.2/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/4.2/howto/static-files/ + +STATIC_URL = "static/" +STATIC_ROOT = os.path.join(BASE_DIR, "static") + +# Default primary key field type +# https://docs.djangoproject.com/en/4.2/ref/settings/#default-auto-field + +DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField" diff --git a/backend/requirements.txt b/backend/requirements.txt index f602d9ed..f90f2ca8 100644 --- a/backend/requirements.txt +++ b/backend/requirements.txt @@ -1,10 +1,10 @@ -asgiref==3.7.2 -Django==4.2.3 -django-filter==23.2 -djangorestframework==3.14.0 -gunicorn==20.1.0 -Markdown==3.4.3 -packaging==23.1 -psycopg2==2.9.6 -pytz==2023.3 -sqlparse==0.4.4 +asgiref==3.7.2 +Django==4.2.3 +django-filter==23.2 +djangorestframework==3.14.0 +gunicorn==20.1.0 +Markdown==3.4.3 +packaging==23.1 +psycopg2==2.9.6 +pytz==2023.3 +sqlparse==0.4.4 diff --git a/backend/start.sh b/backend/start.sh index 4e1b688f..1dbdaa3e 100755 --- a/backend/start.sh +++ b/backend/start.sh @@ -1,4 +1,4 @@ -#! /bin/bash +#! /bin/sh echo "started setup" diff --git a/docker-compose.yml b/docker-compose.yml index 8b203ed3..433685d5 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,80 +1,80 @@ -version: '3.1' - -services: - postgres: - image: postgres:${POSTGRES_VERSION} - restart: always - env_file: - - .env - expose: - - ${POSTGRES_PORT} - healthcheck: - test: ["CMD-SHELL", "pg_isready", "-U corpus"] - interval: 30s - timeout: 30s - retries: 5 - start_period: 30s - networks: - - corpus_network - volumes: - - postgres_data:/var/lib/postgresql/data - - adminer: - image: adminer - restart: always - expose: - - ${ADMINER_PORT} - env_file: - - .env - networks: - - corpus_network - - backend: - build: backend - command: /corpus/start.sh - restart: always - expose: - - ${DJANGO_BACKEND_PORT} - networks: - - corpus_network - volumes: - - static_files:/corpus/static - depends_on: - postgres: - condition: service_healthy - env_file: - - .env - - frontend: - build: frontend - restart: always - command: node build - networks: - - corpus_network - depends_on: - postgres: - condition: service_healthy - expose: - - "3000" - - nginx: - build: nginx - restart: always - depends_on: - - backend - - postgres - networks: - - corpus_network - ports: - - "80:80" - volumes: - - static_files:/etc/nginx/staticfiles - env_file: - - .env - -networks: - corpus_network: - -volumes: - static_files: - postgres_data: +version: '3.1' + +services: + postgres: + image: postgres:${POSTGRES_VERSION} + restart: always + env_file: + - .env + expose: + - ${POSTGRES_PORT} + healthcheck: + test: ["CMD-SHELL", "pg_isready", "-U corpus"] + interval: 30s + timeout: 30s + retries: 5 + start_period: 30s + networks: + - corpus_network + volumes: + - postgres_data:/var/lib/postgresql/data + + adminer: + image: adminer + restart: always + expose: + - ${ADMINER_PORT} + env_file: + - .env + networks: + - corpus_network + + backend: + build: backend + command: /corpus/start.sh + restart: always + expose: + - ${DJANGO_BACKEND_PORT} + networks: + - corpus_network + volumes: + - static_files:/corpus/static + depends_on: + postgres: + condition: service_healthy + env_file: + - .env + + frontend: + build: frontend + restart: always + command: node build + networks: + - corpus_network + depends_on: + postgres: + condition: service_healthy + expose: + - "3000" + + nginx: + build: nginx + restart: always + depends_on: + - backend + - postgres + networks: + - corpus_network + ports: + - "80:80" + volumes: + - static_files:/etc/nginx/staticfiles + env_file: + - .env + +networks: + corpus_network: + +volumes: + static_files: + postgres_data: diff --git a/frontend/package-lock.json b/frontend/package-lock.json index c748be1a..246e52e4 100644 --- a/frontend/package-lock.json +++ b/frontend/package-lock.json @@ -3,6 +3,9 @@ "name": "frontend", "packages": { "": { + "dependencies": { + "winston": "^3.10.0" + }, "devDependencies": { "@storybook/addon-essentials": "^7.1.1", "@storybook/addon-interactions": "^7.1.1", @@ -2206,15 +2209,23 @@ "version": "7.22.5" }, "node_modules/@colors/colors": { - "dev": true, "engines": { "node": ">=0.1.90" }, "integrity": "sha512-ooWCrlZP11i8GImSjTHYHLkvFDP48nS4+204nGb1RiX/WXYHmJA2III9/e2DWVabCESdW7hBAEzHRqUn9OUVvQ==", - "optional": true, "resolved": "https://registry.npmjs.org/@colors/colors/-/colors-1.5.0.tgz", "version": "1.5.0" }, + "node_modules/@dabh/diagnostics": { + "dependencies": { + "colorspace": "1.1.x", + "enabled": "2.0.x", + "kuler": "^2.0.0" + }, + "integrity": "sha512-hrlQOIi7hAfzsMqlGSFyVucrx38O+j6wiGOf//H2ecvIEqYN4ADBSS2iLMh5UFyDunCNniUIPk/q3riFv45xRA==", + "resolved": "https://registry.npmjs.org/@dabh/diagnostics/-/diagnostics-2.0.3.tgz", + "version": "2.0.3" + }, "node_modules/@discoveryjs/json-ext": { "dev": true, "engines": { @@ -5853,6 +5864,11 @@ "resolved": "https://registry.npmjs.org/@types/serve-static/-/serve-static-1.15.2.tgz", "version": "1.15.2" }, + "node_modules/@types/triple-beam": { + "integrity": "sha512-txGIh+0eDFzKGC25zORnswy+br1Ha7hj5cMVwKIU7+s0U2AxxJru/jZSMU6OC9MJWP6+pc/hc6ZjyZShpsyY2g==", + "resolved": "https://registry.npmjs.org/@types/triple-beam/-/triple-beam-1.3.2.tgz", + "version": "1.3.2" + }, "node_modules/@types/unist": { "dev": true, "integrity": "sha512-cputDpIbFgLUaGQn6Vqg3/YsJwxUwHLO13v3i5ouxT4lat0khip9AEWxtERujXV9wxIB1EyF97BSJFt6vpdI8g==", @@ -6539,7 +6555,6 @@ "version": "0.16.1" }, "node_modules/async": { - "dev": true, "integrity": "sha512-iAB+JbDEGXhyIUavoDl9WP/Jj106Kz9DEn1DPgYw5ruDn0e3Wgi3sKFm55sASdGBNOQB8F59d9qQ7deqrHA8wQ==", "resolved": "https://registry.npmjs.org/async/-/async-3.2.4.tgz", "version": "3.2.4" @@ -7208,6 +7223,15 @@ "resolved": "https://registry.npmjs.org/code-red/-/code-red-1.0.3.tgz", "version": "1.0.3" }, + "node_modules/color": { + "dependencies": { + "color-convert": "^1.9.3", + "color-string": "^1.6.0" + }, + "integrity": "sha512-aBl7dZI9ENN6fUGC7mWpMTPNHmWUSNan9tuWN6ahh5ZLNk9baLJOnSMlrQkHcrfFgz2/RigjUVAjdx36VcemKA==", + "resolved": "https://registry.npmjs.org/color/-/color-3.2.1.tgz", + "version": "3.2.1" + }, "node_modules/color-convert": { "dependencies": { "color-name": "~1.1.4" @@ -7221,11 +7245,32 @@ "version": "2.0.1" }, "node_modules/color-name": { - "dev": true, "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==", "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz", "version": "1.1.4" }, + "node_modules/color-string": { + "dependencies": { + "color-name": "^1.0.0", + "simple-swizzle": "^0.2.2" + }, + "integrity": "sha512-shrVawQFojnZv6xM40anx4CkoDP+fZsw/ZerEMsW/pyzsRbElpsL/DBVW7q3ExxwusdNXI3lXpuhEZkzs8p5Eg==", + "resolved": "https://registry.npmjs.org/color-string/-/color-string-1.9.1.tgz", + "version": "1.9.1" + }, + "node_modules/color/node_modules/color-convert": { + "dependencies": { + "color-name": "1.1.3" + }, + "integrity": "sha512-QfAUtd+vFdAtFQcC8CCyYt1fYWxSqAiK2cSD6zDB8N3cpsEBAvRxp9zOGg6G/SHHJYAT88/az/IuDGALsNVbGg==", + "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-1.9.3.tgz", + "version": "1.9.3" + }, + "node_modules/color/node_modules/color-name": { + "integrity": "sha512-72fSenhMw2HZMTVHeCA9KCmpEIbzWiQsjN+BHcBbS9vr1mtt+vJjPdksIBNUmKAW8TFUDPJK5SUU3QhE9NEXDw==", + "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.3.tgz", + "version": "1.1.3" + }, "node_modules/colord": { "dev": true, "integrity": "sha512-jeC1axXpnb0/2nn/Y1LPuLdgXBLH7aDcHu4KEKfqw3CUhX7ZpfBSlPKyqXE6btIgEzfWtrX3/tyBCaCvXvMkOw==", @@ -7238,6 +7283,15 @@ "resolved": "https://registry.npmjs.org/colorette/-/colorette-2.0.20.tgz", "version": "2.0.20" }, + "node_modules/colorspace": { + "dependencies": { + "color": "^3.1.3", + "text-hex": "1.0.x" + }, + "integrity": "sha512-BgvKJiuVu1igBUF2kEjRCZXol6wiiGbY5ipL/oVPwm0BL9sIpMIzM8IK7vwuxIIzOXMV3Ey5w+vxhm0rR/TN8w==", + "resolved": "https://registry.npmjs.org/colorspace/-/colorspace-1.1.4.tgz", + "version": "1.1.4" + }, "node_modules/combined-stream": { "dependencies": { "delayed-stream": "~1.0.0" @@ -8050,6 +8104,11 @@ "resolved": "https://registry.npmjs.org/emojis-list/-/emojis-list-3.0.0.tgz", "version": "3.0.0" }, + "node_modules/enabled": { + "integrity": "sha512-AKrN98kuwOzMIdAizXGI86UFBoo26CL21UM763y1h/GMSJ4/OHU9k2YlsmBpyScFo/wbLzWQJBMCW4+IO3/+OQ==", + "resolved": "https://registry.npmjs.org/enabled/-/enabled-2.0.0.tgz", + "version": "2.0.0" + }, "node_modules/encodeurl": { "dev": true, "engines": { @@ -8836,6 +8895,11 @@ "resolved": "https://registry.npmjs.org/fd-slicer/-/fd-slicer-1.1.0.tgz", "version": "1.1.0" }, + "node_modules/fecha": { + "integrity": "sha512-OP2IUU6HeYKJi3i0z4A19kHMQoLVs4Hc+DPqqxI2h/DPZHTm/vjsfC6P0b4jCMy14XizLBqvndQ+UilD7707Jw==", + "resolved": "https://registry.npmjs.org/fecha/-/fecha-4.2.3.tgz", + "version": "4.2.3" + }, "node_modules/fetch-retry": { "dev": true, "integrity": "sha512-3yurQZ2hD9VISAhJJP9bpYFNQrHHBXE2JxxjY5aLEcDi46RmAzJE2OC9FAde0yis5ElW0jTTzs0zfg/Cca4XqQ==", @@ -9064,6 +9128,11 @@ "resolved": "https://registry.npmjs.org/flow-parser/-/flow-parser-0.213.1.tgz", "version": "0.213.1" }, + "node_modules/fn.name": { + "integrity": "sha512-GRnmB5gPyJpAhTQdSZTSp9uaPSvl09KoYcMQtsB9rQoOmzs9dH6ffeccH+Z+cv6P68Hu5bC6JjRh4Ah/mHSNRw==", + "resolved": "https://registry.npmjs.org/fn.name/-/fn.name-1.1.0.tgz", + "version": "1.1.0" + }, "node_modules/for-each": { "dependencies": { "is-callable": "^1.1.3" @@ -9715,7 +9784,6 @@ "version": "1.0.6" }, "node_modules/inherits": { - "dev": true, "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==", "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz", "version": "2.0.4" @@ -10104,7 +10172,6 @@ "version": "1.0.2" }, "node_modules/is-stream": { - "dev": true, "engines": { "node": ">=8" }, @@ -10575,6 +10642,11 @@ "resolved": "https://registry.npmjs.org/known-css-properties/-/known-css-properties-0.27.0.tgz", "version": "0.27.0" }, + "node_modules/kuler": { + "integrity": "sha512-Xq9nH7KlWZmXAtodXDDRE7vs6DU1gTU8zYDHDiWLSip45Egwq3plLHzPn27NgvzL2r1LMPC1vdqh98sQxtqj4A==", + "resolved": "https://registry.npmjs.org/kuler/-/kuler-2.0.0.tgz", + "version": "2.0.0" + }, "node_modules/lazy-universal-dotenv": { "dependencies": { "app-root-dir": "^1.0.2", @@ -10812,6 +10884,19 @@ "resolved": "https://registry.npmjs.org/log-symbols/-/log-symbols-4.1.0.tgz", "version": "4.1.0" }, + "node_modules/logform": { + "dependencies": { + "@colors/colors": "1.5.0", + "@types/triple-beam": "^1.3.2", + "fecha": "^4.2.0", + "ms": "^2.1.1", + "safe-stable-stringify": "^2.3.1", + "triple-beam": "^1.3.0" + }, + "integrity": "sha512-9FyqAm9o9NKKfiAKfZoYo9bGXXuwMkxQiQttkT4YjjVtQVIQtK6LmVtlxmCaFswo6N4AfEkHqZTV0taDtPotNg==", + "resolved": "https://registry.npmjs.org/logform/-/logform-2.5.1.tgz", + "version": "2.5.1" + }, "node_modules/loose-envify": { "bin": { "loose-envify": "cli.js" @@ -11159,7 +11244,6 @@ "version": "1.0.1" }, "node_modules/ms": { - "dev": true, "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==", "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", "version": "2.1.2" @@ -11465,6 +11549,14 @@ "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", "version": "1.4.0" }, + "node_modules/one-time": { + "dependencies": { + "fn.name": "1.x.x" + }, + "integrity": "sha512-5DXOiRKwuSEcQ/l0kGCF6Q3jcADFv5tSmRaJck/OqkVFcOzutB134KRSfF0xDrL39MNnqxbHBbUUcjZIhTgb2g==", + "resolved": "https://registry.npmjs.org/one-time/-/one-time-1.0.0.tgz", + "version": "1.0.0" + }, "node_modules/onetime": { "dependencies": { "mimic-fn": "^2.1.0" @@ -12660,7 +12752,6 @@ "string_decoder": "^1.1.1", "util-deprecate": "^1.0.1" }, - "dev": true, "engines": { "node": ">= 6" }, @@ -12981,7 +13072,6 @@ "version": "1.8.1" }, "node_modules/safe-buffer": { - "dev": true, "funding": [ { "type": "github", @@ -13000,6 +13090,14 @@ "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.1.tgz", "version": "5.2.1" }, + "node_modules/safe-stable-stringify": { + "engines": { + "node": ">=10" + }, + "integrity": "sha512-e2bDA2WJT0wxseVd4lsDP4+3ONX6HpMXQa1ZhFQ7SU+GjvORCmShbCMltrtIDfkYhVHrOcPtj+KhmDBdPdZD1g==", + "resolved": "https://registry.npmjs.org/safe-stable-stringify/-/safe-stable-stringify-2.4.3.tgz", + "version": "2.4.3" + }, "node_modules/safer-buffer": { "dev": true, "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==", @@ -13293,6 +13391,19 @@ "resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-3.0.7.tgz", "version": "3.0.7" }, + "node_modules/simple-swizzle": { + "dependencies": { + "is-arrayish": "^0.3.1" + }, + "integrity": "sha512-JA//kQgZtbuY83m+xT+tXJkmJncGMTFT+C+g2h2R9uxkYIrE2yy9sgmcLhCnw57/WSD+Eh3J97FPEDFnbXnDUg==", + "resolved": "https://registry.npmjs.org/simple-swizzle/-/simple-swizzle-0.2.2.tgz", + "version": "0.2.2" + }, + "node_modules/simple-swizzle/node_modules/is-arrayish": { + "integrity": "sha512-eVRqCvVlZbuw3GrM63ovNSNAeA1K16kaR/LRY/92w0zxQ5/1YzwblUX652i4Xs9RwAGjW9d9y6X88t8OaAJfWQ==", + "resolved": "https://registry.npmjs.org/is-arrayish/-/is-arrayish-0.3.2.tgz", + "version": "0.3.2" + }, "node_modules/simple-update-notifier": { "dependencies": { "semver": "~7.0.0" @@ -13434,6 +13545,14 @@ "resolved": "https://registry.npmjs.org/sprintf-js/-/sprintf-js-1.0.3.tgz", "version": "1.0.3" }, + "node_modules/stack-trace": { + "engines": { + "node": "*" + }, + "integrity": "sha512-KGzahc7puUKkzyMt+IqAep+TVNbKP+k2Lmwhub39m1AsTSkaDutx56aDCo+HLDzf/D26BIHTJWNiTG1KAJiQCg==", + "resolved": "https://registry.npmjs.org/stack-trace/-/stack-trace-0.0.10.tgz", + "version": "0.0.10" + }, "node_modules/statuses": { "dev": true, "engines": { @@ -13526,7 +13645,6 @@ "dependencies": { "safe-buffer": "~5.2.0" }, - "dev": true, "integrity": "sha512-hkRX8U1WjJFd8LsDJ2yQ/wWWxaopEsABU1XfkM8A+j0+85JAGppt16cr1Whg6KIbb4okU6Mql6BOj+uup/wKeA==", "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.3.0.tgz", "version": "1.3.0" @@ -14322,6 +14440,11 @@ "resolved": "https://registry.npmjs.org/test-exclude/-/test-exclude-6.0.0.tgz", "version": "6.0.0" }, + "node_modules/text-hex": { + "integrity": "sha512-uuVGNWzgJ4yhRaNSiubPY7OjISw4sw4E5Uv0wbjp+OzcbmVU/rsT8ujgcXJhn9ypzsgr5vlzpPqP+MBBKcGvbg==", + "resolved": "https://registry.npmjs.org/text-hex/-/text-hex-1.0.0.tgz", + "version": "1.0.0" + }, "node_modules/text-table": { "dev": true, "integrity": "sha512-N+8UisAXDGk8PFXP4HAzVR9nbfmVJ3zYLAWiTIoqC5v5isinhr+r5uaO8+7r3BMfuNIufIsA7RdpVgacC2cSpw==", @@ -14458,6 +14581,14 @@ "resolved": "https://registry.npmjs.org/tr46/-/tr46-0.0.3.tgz", "version": "0.0.3" }, + "node_modules/triple-beam": { + "engines": { + "node": ">= 14.0.0" + }, + "integrity": "sha512-aZbgViZrg1QNcG+LULa7nhZpJTZSLm/mXnHXnbAbjmN5aSa0y7V+wvv6+4WaBtpISJzThKy+PIPxc1Nq1EJ9mg==", + "resolved": "https://registry.npmjs.org/triple-beam/-/triple-beam-1.4.1.tgz", + "version": "1.4.1" + }, "node_modules/ts-dedent": { "dev": true, "engines": { @@ -14777,7 +14908,6 @@ "version": "0.12.5" }, "node_modules/util-deprecate": { - "dev": true, "integrity": "sha512-EPD5q1uXyFxJpCrLnCc1nHnq3gOa6DZBocAIiI2TaSCA7VCJ1UJDMagCzIkXNsUYfD1daK//LTEQ8xiIbrHtcw==", "resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz", "version": "1.0.2" @@ -15069,6 +15199,40 @@ "resolved": "https://registry.npmjs.org/which-typed-array/-/which-typed-array-1.1.11.tgz", "version": "1.1.11" }, + "node_modules/winston": { + "dependencies": { + "@colors/colors": "1.5.0", + "@dabh/diagnostics": "^2.0.2", + "async": "^3.2.3", + "is-stream": "^2.0.0", + "logform": "^2.4.0", + "one-time": "^1.0.0", + "readable-stream": "^3.4.0", + "safe-stable-stringify": "^2.3.1", + "stack-trace": "0.0.x", + "triple-beam": "^1.3.0", + "winston-transport": "^4.5.0" + }, + "engines": { + "node": ">= 12.0.0" + }, + "integrity": "sha512-nT6SIDaE9B7ZRO0u3UvdrimG0HkB7dSTAgInQnNR2SOPJ4bvq5q79+pXLftKmP52lJGW15+H5MCK0nM9D3KB/g==", + "resolved": "https://registry.npmjs.org/winston/-/winston-3.10.0.tgz", + "version": "3.10.0" + }, + "node_modules/winston-transport": { + "dependencies": { + "logform": "^2.3.2", + "readable-stream": "^3.6.0", + "triple-beam": "^1.3.0" + }, + "engines": { + "node": ">= 6.4.0" + }, + "integrity": "sha512-YpZzcUzBedhlTAfJg6vJDlyEai/IFMIVcaEZZyl3UXIl4gmqRpU7AE89AHLkbzLUsv0NVmw7ts+iztqKxxPW1Q==", + "resolved": "https://registry.npmjs.org/winston-transport/-/winston-transport-4.5.0.tgz", + "version": "4.5.0" + }, "node_modules/wordwrap": { "dev": true, "integrity": "sha512-gvVzJFlPycKc5dZN4yPkP8w7Dc37BtP1yczEneOb4uq34pXZcvrtRTmWV8W+Ume+XCxKgbjM+nevkyFPMybd4Q==", diff --git a/frontend/package.json b/frontend/package.json index 48b1184f..1916076b 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -1,4 +1,7 @@ { + "dependencies": { + "winston": "^3.10.0" + }, "devDependencies": { "@storybook/addon-essentials": "^7.1.1", "@storybook/addon-interactions": "^7.1.1", diff --git a/frontend/src/hooks.server.ts b/frontend/src/hooks.server.ts new file mode 100644 index 00000000..41a8f9ef --- /dev/null +++ b/frontend/src/hooks.server.ts @@ -0,0 +1,17 @@ +import winston from "winston"; +import { inspect } from "util"; + +const logger = winston.createLogger({ + level: 'info', + format: winston.format.json(), + defaultMeta: { service: 'corpus-frontend' }, + transports: [ + new winston.transports.Console({ format: winston.format.simple() }), // Has to be changed to file once log monitoring is enabled. + ], +}); + +export async function handle({ event, resolve }) { + const response = await resolve(event); + logger.info(inspect(event)); + return response; +} diff --git a/nginx/Dockerfile b/nginx/Dockerfile index d74e13fe..3affba7e 100644 --- a/nginx/Dockerfile +++ b/nginx/Dockerfile @@ -1,4 +1,6 @@ -FROM nginx:stable-alpine - -COPY default.conf /etc/nginx -COPY default.conf /etc/nginx/conf.d +FROM nginx:stable-alpine + +RUN mkdir /logs + +COPY default.conf /etc/nginx +COPY default.conf /etc/nginx/conf.d diff --git a/nginx/default.conf b/nginx/default.conf index 83650572..0bd89bd7 100644 --- a/nginx/default.conf +++ b/nginx/default.conf @@ -2,6 +2,9 @@ server { listen 80; server_name corpus_server; + error_log /logs/error.log warn; + access_log /logs/access.log; + location / { proxy_pass http://frontend:3000; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; From 2a2a83c9e632536b6dd5e200ff51dfc58e1b5aa7 Mon Sep 17 00:00:00 2001 From: Nishant Nayak Date: Sun, 30 Jul 2023 23:17:21 +0530 Subject: [PATCH 2/2] Fix STATIC_URL so that static assets load in DEVELOPMENT Signed-off-by: Nishant Nayak --- backend/corpus/settings.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/backend/corpus/settings.py b/backend/corpus/settings.py index 93d1101c..f5e18245 100644 --- a/backend/corpus/settings.py +++ b/backend/corpus/settings.py @@ -138,8 +138,11 @@ # Static files (CSS, JavaScript, Images) # https://docs.djangoproject.com/en/4.2/howto/static-files/ -STATIC_URL = "static/" -STATIC_ROOT = os.path.join(BASE_DIR, "static") +if not DEBUG: + STATIC_URL = "static/" + STATIC_ROOT = os.path.join(BASE_DIR, "static") +else: + STATIC_URL = "/api/static/" # Default primary key field type # https://docs.djangoproject.com/en/4.2/ref/settings/#default-auto-field