diff --git a/.buildpacks b/.buildpacks deleted file mode 100755 index 68f0244..0000000 --- a/.buildpacks +++ /dev/null @@ -1,2 +0,0 @@ -https://github.com/heroku/heroku-buildpack-nodejs.git#v91 -https://github.com/heroku/heroku-buildpack-python.git#v82 diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..4f44a06 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,38 @@ +# VCS and CI +.git +.gitignore +.github + +# Dependencies and build output (rebuilt inside the image) +node_modules/ +oh_queue/static/public/ +oh_queue/static/.webassets-cache/ + +# Local Python environments and caches +venv/ +.venv +__pycache__/ +*.py[cod] +.pytest_cache/ + +# Secrets and local config - never bake these into an image +.env* +*credentials*.json + +# Local databases and exports +*.db +*.sql + +# Tests and dev-only files +tests/ +pytest.ini +.coverage +coverage.xml +requirements-dev.txt +codecov.yml +.flake8 +.flowconfig +mise.toml +docs/ +README.md +**/.DS_Store diff --git a/.env.example b/.env.example index edb6523..774dfcc 100644 --- a/.env.example +++ b/.env.example @@ -3,12 +3,17 @@ # dev or prod. Required: the app won't start without it. ENV=dev FLASK_APP=manage.py -EVENTLET_NO_GREENDNS=yes # Required outside development. SECRET_KEY= -# Required outside development; in development the app uses app.db (SQLite). +# Required outside development, unless CLOUD_SQL_INSTANCE is set; in +# development the app uses app.db (SQLite). DATABASE_URL= +# Deployments connect to Cloud SQL as the service account they run as (IAM +# database auth, so no password) instead of using DATABASE_URL. +# CLOUD_SQL_INSTANCE=project:region:instance +# DB_USER=service-account@project.iam +# DB_NAME=oh # Canvas developer key. Locally, use the UC Berkeley sandbox key: # https://ucberkeleysandbox.instructure.com/ diff --git a/.github/workflows/pr-staging.yml b/.github/workflows/pr-staging.yml new file mode 100644 index 0000000..07ca015 --- /dev/null +++ b/.github/workflows/pr-staging.yml @@ -0,0 +1,127 @@ +name: PR Preview Deployment + +on: + pull_request: + types: [opened, synchronize, reopened, closed] + +permissions: + contents: read + +env: + # Keyless auth via Workload Identity Federation; only this repository may + # impersonate the deployer service account. + WORKLOAD_IDENTITY_PROVIDER: projects/137456085712/locations/global/workloadIdentityPools/github/providers/berkeley-cdss + DEPLOYER_SERVICE_ACCOUNT: oh-gh-actions-deployer@staging-cdss-web-apps.iam.gserviceaccount.com + +# One deploy per PR at a time; a newer push supersedes an in-progress deploy. +concurrency: + group: preview-oh-pr-${{ github.event.number }} + cancel-in-progress: true + +# Fork PRs get no OIDC token, and their code shouldn't run with staging secrets, +# so previews only deploy for branches in this repository. Dependabot PRs are +# skipped too: they run their own changed workflows before review, so a bumped +# action pin would otherwise get the deployer's GCP access unreviewed. +jobs: + cleanup-preview-service: + if: github.event.action == 'closed' && github.event.pull_request.head.repo.full_name == github.repository && github.event.pull_request.user.login != 'dependabot[bot]' + runs-on: ubuntu-latest + permissions: + # Lets google-github-actions/auth exchange GitHub's OIDC token for GCP credentials. + id-token: write + steps: + - id: auth + uses: google-github-actions/auth@7c6bc770dae815cd3e89ee6cdf493a5fab2cc093 # v3.0.0 + with: + workload_identity_provider: ${{ env.WORKLOAD_IDENTITY_PROVIDER }} + service_account: ${{ env.DEPLOYER_SERVICE_ACCOUNT }} + + - name: Delete Cloud Run Preview Service + run: | + gcloud run services delete preview-oh-pr-${{ github.event.number }} \ + --region=us-west1 \ + --quiet || true + + deploy-preview-service: + if: github.event.action != 'closed' && github.event.pull_request.head.repo.full_name == github.repository && github.event.pull_request.user.login != 'dependabot[bot]' + runs-on: ubuntu-latest + permissions: + contents: read + # Lets google-github-actions/auth exchange GitHub's OIDC token for GCP credentials. + id-token: write + # Lets the deploy job comment the preview URL on the PR. + issues: write + pull-requests: write + steps: + - name: Checkout Code + uses: actions/checkout@v7 + with: + ref: ${{ github.head_ref }} + + - id: auth + uses: google-github-actions/auth@7c6bc770dae815cd3e89ee6cdf493a5fab2cc093 # v3.0.0 + with: + workload_identity_provider: ${{ env.WORKLOAD_IDENTITY_PROVIDER }} + service_account: ${{ env.DEPLOYER_SERVICE_ACCOUNT }} + + - name: Set up Cloud SDK + uses: google-github-actions/setup-gcloud@aa5489c8933f4cc7a4f7d45035b3b1440c9c10db # v3.0.1 + + - name: Deploy to Cloud Run (Preview) + id: deploy + uses: google-github-actions/deploy-cloudrun@2028e2d7d30a78c6910e0632e48dd561b064884d # v3.0.1 + with: + service: preview-oh-pr-${{ github.event.number }} + region: us-west1 + source: . + # The image is built as oh-build, which can only build, not as the default compute + # service account, which has Editor on the project. + flags: '--allow-unauthenticated --service-account=oh-app@staging-cdss-web-apps.iam.gserviceaccount.com --build-service-account=projects/staging-cdss-web-apps/serviceAccounts/oh-build@staging-cdss-web-apps.iam.gserviceaccount.com --max-instances=3' + # RUN_MIGRATIONS is never set here: previews share the staging database. + env_vars: | + ENV=prod + # Lets the app explain that a PR adding a migration can't run as a preview. + PREVIEW_PR=${{ github.event.number }} + CANVAS_SERVER_URL=https://ucberkeley.test.instructure.com/ + ADMIN_OVERRIDE_CANVAS_COURSE_ID=1549197 + # Cloud SQL IAM database auth as the service's own account; no password. + CLOUD_SQL_INSTANCE=staging-cdss-web-apps:us-west1:staging-cdss-web-apps-2 + DB_USER=oh-app@staging-cdss-web-apps.iam + DB_NAME=oh + secrets: | + CANVAS_CLIENT_ID=oh-canvas-client-id:latest + CANVAS_CLIENT_SECRET=oh-canvas-client-secret:latest + SECRET_KEY=oh-secret-key:latest + LLM_TIPS_ENDPOINT=oh-llm-tips-endpoint:latest + LLM_TIPS_AUTH_TOKEN=oh-llm-tips-auth-token:latest + + - name: Allow Unauthenticated Access (allUsers) + run: | + gcloud run services add-iam-policy-binding preview-oh-pr-${{ github.event.number }} \ + --region=us-west1 \ + --member="allUsers" \ + --role="roles/run.invoker" + + - name: Comment PR with Preview URL + uses: actions/github-script@v7 + env: + PREVIEW_URL: https://preview-oh-pr-${{ github.event.number }}-137456085712.us-west1.run.app + with: + script: | + // The preview URL is stable for the life of the PR, so only comment once. + const marker = ''; + const comments = await github.paginate(github.rest.issues.listComments, { + issue_number: context.issue.number, + owner: context.repo.owner, + repo: context.repo.repo, + }); + if (comments.some(c => c.body?.includes(marker))) { + core.info('Preview URL already commented; skipping.'); + return; + } + await github.rest.issues.createComment({ + issue_number: context.issue.number, + owner: context.repo.owner, + repo: context.repo.repo, + body: `${marker}\nšŸš€ **Staging Preview Deployed!**\n\nURL: ${process.env.PREVIEW_URL}` + }); diff --git a/Dockerfile b/Dockerfile index fd058a2..e8a5cbe 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,19 +1,81 @@ -FROM python:3.14-slim +# syntax=docker/dockerfile:1 + +# Image for deploying the office hours queue to Google Cloud Run, like seating's +# and sections'. + +# --------------------------------------------------------------------------- +# Node packages +# +# Babel, which compiles the React components into one script in the build stage. +# --------------------------------------------------------------------------- +FROM node:24-slim AS node + +WORKDIR /build +COPY package.json yarn.lock ./ +# Babel is in dependencies; devDependencies only has Flow, which the build doesn't use. +RUN yarn install --frozen-lockfile --production -ENV APP_HOME /app -ENV FLASK_APP=manage.py -ENV PYTHONPATH=$PYTHONPATH:. +# --------------------------------------------------------------------------- +# Build stage +# +# Installs the Python dependencies into a venv that is copied into the runtime +# stage, so pip and its build cache stay out of the shipped image, then builds +# the frontend: in production the app serves oh_queue/static/public/common.js +# and style.css as they are (oh_queue/assets.py), so `flask build` makes them +# here, with Node, which the runtime image doesn't need. +# --------------------------------------------------------------------------- +FROM python:3.14-slim AS builder -WORKDIR $APP_HOME -COPY . ./ +ENV PIP_DISABLE_PIP_VERSION_CHECK=1 \ + PIP_NO_CACHE_DIR=1 +RUN python -m venv /opt/venv +ENV PATH="/opt/venv/bin:$PATH" + +# Copied on its own so the dependency layer is only rebuilt when the pins change. +COPY requirements.txt ./ RUN pip install -r requirements.txt -# execution permissions -RUN chmod +x /app/entrypoint.sh +COPY --from=node /usr/local/bin/node /usr/local/bin/node +WORKDIR /build +COPY --from=node /build/node_modules ./node_modules +COPY . . +# `flask build` refuses to run in production, and in development needs no +# settings: it renders the queue page once, which compiles the bundles. +RUN ENV=dev FLASK_APP=manage.py PYTHONPATH=. flask build + +# --------------------------------------------------------------------------- +# Runtime stage +# --------------------------------------------------------------------------- +FROM python:3.14-slim + +RUN useradd --create-home --uid 1000 app + +COPY --from=builder /opt/venv /opt/venv + +ENV PATH="/opt/venv/bin:$PATH" \ + PYTHONUNBUFFERED=1 \ + PYTHONDONTWRITEBYTECODE=1 \ + PYTHONPATH=. \ + FLASK_APP=manage.py \ + PORT=8080 + +WORKDIR /app +# Owned by the app user: webassets writes its cache in oh_queue/static. +COPY --chown=app:app . . +COPY --from=builder --chown=app:app /build/oh_queue/static/public ./oh_queue/static/public + +USER app + +EXPOSE 8080 -# Set the entrypoint -ENTRYPOINT ["/app/entrypoint.sh"] +HEALTHCHECK --interval=30s --timeout=5s --start-period=20s --retries=3 \ + CMD python -c 'import os, urllib.request; urllib.request.urlopen("http://127.0.0.1:" + os.environ.get("PORT", "8080") + "/health")' -# The page polls the server, so plain threads are enough; eventlet isn't needed. -CMD gunicorn -b :$PORT --workers 4 --threads 8 --timeout 120 manage:app +# With RUN_MIGRATIONS=true (set on staging and production, never on PR previews, +# which share the staging database), apply database migrations before starting. +# `exec` keeps gunicorn as PID 1 so it gets SIGTERM directly on redeploy. +# One worker process with threads, as in seating and sections: Cloud Run's +# default instance is 1 vCPU, and the page polls the server, so requests are +# short and I/O-bound. Override WEB_CONCURRENCY / GUNICORN_THREADS to tune. +CMD ["sh", "-c", "if [ \"$RUN_MIGRATIONS\" = true ]; then flask db upgrade || exit 1; fi; exec gunicorn -b 0.0.0.0:${PORT:-8080} manage:app --workers ${WEB_CONCURRENCY:-1} --threads ${GUNICORN_THREADS:-8} --timeout ${GUNICORN_TIMEOUT:-120} --access-logfile -"] diff --git a/README.md b/README.md index 154729c..87e07b4 100755 --- a/README.md +++ b/README.md @@ -29,6 +29,12 @@ Then open http://localhost:3000/offerings/157/ (the course `seed_data` sets up) `seed_data` adds sample assignments, locations, students and tickets. `python manage.py resetdb` starts the database over. +## Deployment + +The app runs on Google Cloud Run, like seating and sections, from the `Dockerfile`: one non-root gunicorn worker with threads, with a health check at `/health`. The image builds the frontend with `flask build`, since in production the app serves `oh_queue/static/public/` as it is. It connects to Cloud SQL as the service account it runs as (`CLOUD_SQL_INSTANCE`, `DB_USER`, `DB_NAME`), so no database password is stored, and gets its other secrets from Secret Manager. + +Each pull request from a branch in this repository is deployed as a preview on the staging project (`.github/workflows/pr-staging.yml`), and the preview's URL is commented on the PR. Previews share the staging database and never run migrations; see [docs/migrations.md](docs/migrations.md). + ## Running tests With the packages installed as above: diff --git a/config.py b/config.py index a10c485..12525bf 100755 --- a/config.py +++ b/config.py @@ -32,11 +32,48 @@ def required(name, dev_default=None): REMEMBER_COOKIE_HTTPONLY = True REMEMBER_COOKIE_SAMESITE = "Lax" -SQLALCHEMY_DATABASE_URI = required( - "DATABASE_URL", dev_default="sqlite:///" + os.path.join(basedir, "app.db") -) + +def _cloud_sql_creator(instance, user, db): + """Connect to Cloud SQL with IAM database authentication, as the service + account the app runs as, so no database password is stored. Copied from + sections (server/config.py). + + Cloud Run's built-in /cloudsql socket can't do IAM login, hence the connector. + """ + import threading + + from google.cloud.sql.connector import Connector + + connector = None + lock = threading.Lock() + + def connect(): + # Made on the first connection, not when this module is imported, so + # loading the settings doesn't look up Google credentials. + nonlocal connector + with lock: + if connector is None: + # Lazy refresh suits Cloud Run, where CPU is throttled between requests. + connector = Connector(refresh_strategy="lazy") + return connector.connect(instance, "pg8000", user=user, db=db, enable_iam_auth=True) + + return connect + + +# The database: Cloud SQL with IAM auth (CLOUD_SQL_INSTANCE, DB_USER, DB_NAME) +# when deployed, otherwise DATABASE_URL, or in development a local SQLite file. +SQLALCHEMY_ENGINE_OPTIONS = {"pool_pre_ping": True} +CLOUD_SQL_INSTANCE = os.getenv("CLOUD_SQL_INSTANCE") +if CLOUD_SQL_INSTANCE: + SQLALCHEMY_DATABASE_URI = "postgresql+pg8000://" + SQLALCHEMY_ENGINE_OPTIONS["creator"] = _cloud_sql_creator( + CLOUD_SQL_INSTANCE, required("DB_USER"), required("DB_NAME") + ) +else: + SQLALCHEMY_DATABASE_URI = required( + "DATABASE_URL", dev_default="sqlite:///" + os.path.join(basedir, "app.db") + ) SQLALCHEMY_TRACK_MODIFICATIONS = False -DATABASE_CONNECT_OPTIONS = {} LOCAL_TIMEZONE = os.getenv("TIMEZONE", "US/Pacific") diff --git a/docs/migrations.md b/docs/migrations.md new file mode 100644 index 0000000..ae3fab9 --- /dev/null +++ b/docs/migrations.md @@ -0,0 +1,20 @@ +# Database Migrations + +The schema is managed with Flask-Migrate (Alembic); migrations live in `migrations/versions`. To change the schema, edit `oh_queue/models.py`, then from the repository root: + +``` +flask db migrate -m "describe the change" # generates a migration; review and edit it +flask db upgrade # applies it to your local database +``` + +Commit the migration with the model change. Migrations only need to work on Postgres. Deployments with `RUN_MIGRATIONS=true` (staging and production) run `flask db upgrade` when they start. PR previews never run migrations, because they share the staging database and a migration from an unmerged PR could make it unusable for staging. + +## Migrations and PR Previews + +As in sections, the app checks that the database's migration matches the code's latest migration (`oh_queue/schema_check.py`). While they differ, every page, API call and `/health` returns 503, rather than failing on the first query that uses a missing column. The check is repeated at most once a minute. + +This means **a PR that adds a migration can't be tried on its preview.** The preview shares the staging database, which only gets the migration when the PR is merged and staging deploys, so the preview shows "This is a preview of PR #N, which adds a database migration… Merge the PR to see its changes on staging." Test such a PR locally (`flask db upgrade` against your own database), then merge it and check staging. + +The reverse also happens: after another PR with a migration is merged, staging's database is ahead of a preview whose branch doesn't have that migration. The preview then says to merge main into the PR's branch, which redeploys the preview with the migration. + +Locally, the same check tells you to run `flask db upgrade` when your database is behind, for example after pulling a new migration. diff --git a/entrypoint.sh b/entrypoint.sh deleted file mode 100644 index 65eb8bf..0000000 --- a/entrypoint.sh +++ /dev/null @@ -1,12 +0,0 @@ -#!/bin/bash -set -e - -# Tell Flask where the app is -export FLASK_APP=manage.py -export PYTHONPATH=$PYTHONPATH:. - -echo "Applying database migrations..." -flask db upgrade - -echo "Starting Gunicorn..." -exec "$@" \ No newline at end of file diff --git a/migrations/env.py b/migrations/env.py index 156336f..a46b813 100755 --- a/migrations/env.py +++ b/migrations/env.py @@ -1,6 +1,6 @@ from alembic import context from flask import current_app -from sqlalchemy import engine_from_config, pool +from sqlalchemy import text from logging.config import fileConfig import logging @@ -13,8 +13,15 @@ fileConfig(config.config_file_name) logger = logging.getLogger("alembic.env") -# Get the URL from Flask config -db_url = current_app.config.get("SQLALCHEMY_DATABASE_URI") + +# Flask-SQLAlchemy's engine, which connects the way the app does (on Cloud +# Run, with IAM auth through the Cloud SQL connector rather than a URL). +def get_engine(): + return current_app.extensions["migrate"].db.engine + + +# For offline mode, which only needs the URL +db_url = get_engine().url.render_as_string(hide_password=False) # Escape '%' by replacing it with '%%' so Alembic's ConfigParser doesn't trip if db_url: @@ -67,12 +74,6 @@ def process_revision_directives(context, revision, directives): directives[:] = [] logger.info("No changes in schema detected.") - engine = engine_from_config( - config.get_section(config.config_ini_section), - prefix="sqlalchemy.", - poolclass=pool.NullPool, - ) - # Flask-Migrate 4 already sets render_as_batch; a copy, so these callbacks # (which read this run's config) aren't kept for the next command run in # the same process, such as in the tests @@ -80,7 +81,7 @@ def process_revision_directives(context, revision, directives): conf_args.setdefault("render_as_batch", True) conf_args.setdefault("process_revision_directives", process_revision_directives) - connection = engine.connect() + connection = get_engine().connect() context.configure( connection=connection, target_metadata=target_metadata, @@ -89,6 +90,10 @@ def process_revision_directives(context, revision, directives): try: with context.begin_transaction(): + if connection.dialect.name == "postgresql": + # Several Cloud Run instances can start at once; the first takes + # this lock and migrates, and the rest wait, then find nothing to do. + connection.execute(text("SELECT pg_advisory_xact_lock(724502)")) context.run_migrations() finally: connection.close() diff --git a/oh_queue/__init__.py b/oh_queue/__init__.py index 1a6eafb..a169fd7 100755 --- a/oh_queue/__init__.py +++ b/oh_queue/__init__.py @@ -1,10 +1,12 @@ import logging +import os from flask_session import Session from datetime import timedelta from oh_queue.errors import register_error_handlers from oh_queue.login import create_login_client from oh_queue.offerings import create_offering_pages +from oh_queue.schema_check import check_schema_before_requests # Flask-related stuff @@ -26,6 +28,8 @@ logging.basicConfig(level=logging.INFO) +MIGRATIONS_DIR = os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), "migrations") + # Initialize the application app = Flask(__name__) app.config.from_object("config") @@ -55,6 +59,17 @@ app.config['SESSION_COOKIE_SAMESITE'] = 'Lax' Session(app) +# Before the views' hooks, so a database that doesn't match the migrations +# gets an explanation rather than errors from its first query. +check_schema_before_requests(app, MIGRATIONS_DIR) + + +# For Cloud Run and the Dockerfile's health check. +@app.route("/health") +def health(): + return "ok" + + # Import views, which need the app set up first import oh_queue.views # noqa: E402 diff --git a/oh_queue/schema_check.py b/oh_queue/schema_check.py new file mode 100644 index 0000000..48dca24 --- /dev/null +++ b/oh_queue/schema_check.py @@ -0,0 +1,84 @@ +"""Refuse requests while the database's schema doesn't match the code's +migrations, with a message saying why, instead of failing on the first query +that uses a missing column. Copied from sections (server/schema_check.py). + +The usual cause is a PR preview whose PR adds a migration: previews share the +staging database and never run migrations (see the Dockerfile), so the +migration only reaches that database once the PR is merged and staging deploys. +""" + +import os +import time + +import flask +from alembic.migration import MigrationContext +from alembic.script import ScriptDirectory +from flask import current_app, jsonify, request + +from oh_queue.errors import error_page +from oh_queue.models import db + +# How long to trust a result, so most requests don't query the database for it. +CACHE_SECONDS = 60 + + +def schema_problem(migrations_dir: str) -> str | None: + """Why the database doesn't match the code's migrations, or None if it does.""" + script = ScriptDirectory(migrations_dir) + code_heads = set(script.get_heads()) + with db.engine.connect() as connection: + db_heads = set(MigrationContext.configure(connection).get_current_heads()) + if db_heads == code_heads: + return None + + known = {revision.revision for revision in script.walk_revisions()} + pr = os.getenv("PREVIEW_PR") + db_names = ", ".join(sorted(db_heads)) or "none" + code_names = ", ".join(sorted(code_heads)) + if db_heads - known: + # The database has a migration this code doesn't know about. + if pr: + return (f"This is a preview of PR #{pr}, whose branch is older than the staging database " + f"(at migration {db_names}). Merge main into the PR's branch to update the preview.") + return (f"The database is at migration {db_names}, which this version of the Office Hours Queue " + f"doesn't have. Deploy a newer version, or point it at a matching database.") + if pr: + return (f"This is a preview of PR #{pr}, which adds a database migration ({code_names}). " + f"PR previews share the staging database and never run migrations, so this preview " + f"can't run. Merge the PR to see its changes on staging.") + return (f"The database is at migration {db_names}, but this version of the Office Hours Queue " + f"expects {code_names}. Run `flask db upgrade`.") + + +def check_schema_before_requests(app: flask.Flask, migrations_dir: str): + """Refuse requests while the schema doesn't match, unless CHECK_SCHEMA is + off (the tests build their tables with create_all, not migrations).""" + # On the app, so the tests can clear it. + cached = app.extensions["schema_check"] = {"checked_at": None, "problem": None} + + def current_problem(): + now = time.monotonic() + if cached["checked_at"] is None or now - cached["checked_at"] > CACHE_SECONDS: + try: + cached["problem"] = schema_problem(migrations_dir) + except Exception: + # Can't tell (say the database is unreachable): let the request + # run and report its own error, and check again next time. + current_app.logger.exception("Couldn't compare the database schema with the migrations") + return None + cached["checked_at"] = now + return cached["problem"] + + @app.before_request + def refuse_mismatched_schema(): + if not current_app.config.get("CHECK_SCHEMA", True) or request.endpoint == "static": + return None + problem = current_problem() + if problem is None: + return None + if request.path == "/health": + return problem, 503 + # As errors.py answers the course API. + if "/api/" in request.path: + return jsonify({"message": problem}), 503 + return error_page("Database migration needed", problem, 503) diff --git a/oh_queue/static/js/socket.js b/oh_queue/static/js/socket.js index c8019e4..562d16f 100755 --- a/oh_queue/static/js/socket.js +++ b/oh_queue/static/js/socket.js @@ -29,11 +29,12 @@ async function post(endpoint, data, skipTimeout) { return promise; } return timeoutPromise(10000, promise).then((resp) => { - // Refused (no longer enrolled in the course) or gone (the course was - // hidden): if the page itself now fails too, reload it, so it shows the - // server's explanation instead of seeming offline. Checking the page - // first means an API error alone can't make the page reload over and over. - if (resp.status === 403 || resp.status === 404) { + // Refused (no longer enrolled in the course), gone (the course was + // hidden) or unavailable (the database doesn't match the migrations): if + // the page itself now fails too, reload it, so it shows the server's + // explanation instead of seeming offline. Checking the page first means an + // API error alone can't make the page reload over and over. + if (resp.status === 403 || resp.status === 404 || resp.status === 503) { return fetch(window.location.href, { cache: "no-cache" }).then((page) => { if (!page.ok) { window.location.reload(); diff --git a/oh_queue/templates/pages/base.html b/oh_queue/templates/pages/base.html index 864cc2b..077bca4 100644 --- a/oh_queue/templates/pages/base.html +++ b/oh_queue/templates/pages/base.html @@ -30,7 +30,8 @@