Skip to content

Conversation

@MukundC25
Copy link

@MukundC25 MukundC25 commented Dec 19, 2025

Fixes: #1553

What does this PR do?

This PR makes Django stop serving Video Vue app static assets (JS/CSS/maps)
only when explicitly configured, allowing Nginx to serve them instead.

The default behavior remains unchanged.

Why?

Currently, Video Vue static files are served through Django, which is not
ideal in production where Nginx is already in front.

This change allows Nginx to serve those files without breaking:

  • dev environments
  • Django-only deployments
  • index.html server-side injection

What does NOT change?

  • index.html is still served by Django
  • SPA routing is unchanged
  • Default behavior is unchanged

How to enable

Add to your config file (e.g., eventyay.cfg):

[video]
nginx_serve_static = true

## Summary by Sourcery

New Features:
- Introduce a configurable VIDEO_STATIC_NGINX_SERVE setting to control whether Video Vue static assets are served by Django or offloaded to Nginx.

@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Dec 19, 2025

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Makes serving of Video Vue static assets (JS/CSS/map) by Django conditional on a new VIDEO_STATIC_NGINX_SERVE setting, so that when enabled, Nginx is expected to serve those assets while Django continues to serve index.html and handle SPA routing.

Sequence diagram for Video Vue asset request when VIDEO_STATIC_NGINX_SERVE is disabled

sequenceDiagram
    actor Browser
    participant Nginx
    participant Django
    participant VideoAssetView

    Browser->>Nginx: GET /video/app.js
    Nginx->>Django: Proxy /video/app.js
    Django->>VideoAssetView: Dispatch get(path="app.js")
    VideoAssetView->>VideoAssetView: VIDEO_STATIC_NGINX_SERVE == False
    VideoAssetView-->>Django: Return asset content (200)
    Django-->>Nginx: HTTP 200 JS content
    Nginx-->>Browser: HTTP 200 JS content
Loading

Sequence diagram for Video Vue asset request when VIDEO_STATIC_NGINX_SERVE is enabled

sequenceDiagram
    actor Browser
    participant Nginx
    participant Django
    participant VideoAssetView
    participant NginxStatic

    Browser->>Nginx: GET /video/app.js
    Nginx->>Django: Proxy /video/app.js
    Django->>VideoAssetView: Dispatch get(path="app.js")
    VideoAssetView->>VideoAssetView: VIDEO_STATIC_NGINX_SERVE == True
    VideoAssetView->>VideoAssetView: ext in VIDEO_STATIC_NGINX_EXTENSIONS
    VideoAssetView-->>Django: Raise Http404
    Django-->>Nginx: HTTP 404
    Nginx->>NginxStatic: Try serve /video/app.js from static
    NginxStatic-->>Nginx: JS file content
    Nginx-->>Browser: HTTP 200 JS content
Loading

Class diagram for VideoAssetView and related settings

classDiagram
    class DjangoSettings {
        bool VIDEO_STATIC_NGINX_SERVE
    }

    class VideoModuleConstants {
        Path WEBAPP_DIST_DIR
        tuple VIDEO_STATIC_NGINX_EXTENSIONS
    }

    class VideoAssetView {
        +get(request, path, *args, **kwargs)
    }

    DjangoSettings <.. VideoAssetView : reads
    VideoModuleConstants <.. VideoAssetView : uses

    VideoModuleConstants : VIDEO_STATIC_NGINX_EXTENSIONS = (.js, .css, .map)
    DjangoSettings : VIDEO_STATIC_NGINX_SERVE loaded from config[video.nginx_serve_static] with fallback False
    VideoAssetView : get checks VIDEO_STATIC_NGINX_SERVE and path extension to decide 404 or serve from WEBAPP_DIST_DIR
Loading

File-Level Changes

Change Details Files
Introduce an opt-in setting to prevent Django from serving Video Vue static assets so they can be served by Nginx instead.
  • Add VIDEO_STATIC_NGINX_SERVE setting, read from the [video] nginx_serve_static boolean config option with a default of False.
  • Define a list of Video Vue static file extensions that should be handled by Nginx when the setting is enabled (.js, .css, .map).
  • Update the VideoAssetView to raise Http404 for requests to Video Vue static asset paths when VIDEO_STATIC_NGINX_SERVE is True, leaving index.html and SPA routing behavior unchanged.
app/eventyay/config/settings.py
app/eventyay/multidomain/views.py

Possibly linked issues

  • #Video Vue app static files should be served by Nginx: Yes. PR introduces VIDEO_STATIC_NGINX_SERVE so Nginx serves Video Vue JS/CSS/maps while index.html stays on Django.

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@MukundC25 MukundC25 marked this pull request as ready for review December 19, 2025 12:32
Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey there - I've reviewed your changes - here's some feedback:

  • The new VideoAssetView logic uses os.path.splitext but os is not imported in this file in the diff; double‑check that import os is present or add it near the other imports to avoid a NameError.
  • Consider extracting the ('.js', '.css', '.map') extension tuple into a named constant or setting so that it can be shared with the Nginx configuration and easily updated if the set of Video Vue static asset types changes.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The new `VideoAssetView` logic uses `os.path.splitext` but `os` is not imported in this file in the diff; double‑check that `import os` is present or add it near the other imports to avoid a NameError.
- Consider extracting the `('.js', '.css', '.map')` extension tuple into a named constant or setting so that it can be shared with the Nginx configuration and easily updated if the set of Video Vue static asset types changes.

## Individual Comments

### Comment 1
<location> `app/eventyay/multidomain/views.py:133-135` </location>
<code_context>
 class VideoAssetView(View):
     def get(self, request, path='', *args, **kwargs):
+        # When VIDEO_STATIC_NGINX_SERVE is enabled, skip serving static assets
+        if getattr(settings, 'VIDEO_STATIC_NGINX_SERVE', False) and path:
+            _, ext = os.path.splitext(path.lower())
+            if ext in ('.js', '.css', '.map'):
+                raise Http404()
         # Accept empty path -> index handling done by SPA view
</code_context>

<issue_to_address>
**suggestion:** Consider centralizing the list of extensions to be Nginx-served in settings or a constant to avoid future drift.

The extensions are currently hard-coded in the view, so any change to the Nginx-served types (e.g., adding fonts or images) would require a code change here. Exposing this tuple via settings or a shared module-level constant would keep it configurable and reduce the risk of this view falling out of sync with Nginx.

Suggested implementation:

```python
# File extensions that are expected to be served directly by Nginx when
# VIDEO_STATIC_NGINX_SERVE is enabled. Keep this in sync with the Nginx config.
VIDEO_STATIC_NGINX_EXTENSIONS = getattr(
    settings,
    'VIDEO_STATIC_NGINX_EXTENSIONS',
    ('.js', '.css', '.map'),
)


class VideoAssetView(View):

```

```python
        # When VIDEO_STATIC_NGINX_SERVE is enabled, skip serving static assets
        if getattr(settings, 'VIDEO_STATIC_NGINX_SERVE', False) and path:
            _, ext = os.path.splitext(path.lower())
            if ext in VIDEO_STATIC_NGINX_EXTENSIONS:
                raise Http404()

```
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@MukundC25 MukundC25 force-pushed the fix/video-static-nginx branch from b183823 to 1a7cc54 Compare December 19, 2025 12:44
@MukundC25 MukundC25 marked this pull request as draft December 19, 2025 12:44
@MukundC25 MukundC25 marked this pull request as ready for review December 19, 2025 12:47
Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey there - I've reviewed your changes - here's some feedback:

  • Consider using a set instead of a tuple for VIDEO_STATIC_NGINX_EXTENSIONS to make membership checks slightly more efficient and self-descriptive for this lookup use case.
  • You might want to centralize the VIDEO_STATIC_NGINX_SERVE flag usage by referencing settings.VIDEO_STATIC_NGINX_SERVE directly (instead of getattr) to make it clearer that the setting is always defined and reduce defensive code.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Consider using a set instead of a tuple for VIDEO_STATIC_NGINX_EXTENSIONS to make membership checks slightly more efficient and self-descriptive for this lookup use case.
- You might want to centralize the VIDEO_STATIC_NGINX_SERVE flag usage by referencing settings.VIDEO_STATIC_NGINX_SERVE directly (instead of getattr) to make it clearer that the setting is always defined and reduce defensive code.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@MukundC25 MukundC25 force-pushed the fix/video-static-nginx branch from 1a7cc54 to 2f0e48d Compare December 19, 2025 12:52
@MukundC25
Copy link
Author

Addressed the latest Sourcery suggestions:

  • Centralized extensions as a set
  • Referenced settings.VIDEO_STATIC_NGINX_SERVE directly

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR introduces an opt-in configuration setting to allow Nginx to serve Video Vue static assets (JS, CSS, and source maps) instead of Django, improving performance in production deployments. The default behavior remains unchanged, ensuring backward compatibility.

Key Changes:

  • Added VIDEO_STATIC_NGINX_SERVE configuration setting (default: False)
  • Modified VideoAssetView to return 404 for static assets when the setting is enabled, allowing Nginx to handle them
  • Django continues to serve index.html and handle SPA routing regardless of the setting

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
app/eventyay/config/settings.py Adds the VIDEO_STATIC_NGINX_SERVE configuration setting from the [video] config section with a safe default of False
app/eventyay/multidomain/views.py Updates VideoAssetView to skip serving .js, .css, and .map files when the new setting is enabled, delegating to Nginx instead

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Backlog

Development

Successfully merging this pull request may close these issues.

Video Vue app static files should be served by Nginx

2 participants