Skip to content

Conversation

@hamo-o
Copy link
Contributor

@hamo-o hamo-o commented Mar 23, 2025

#️⃣ 연관된 이슈>

📝 작업 내용> 이번 PR에서 작업한 내용을 간략히 설명해주세요(이미지 첨부 가능)

SSR 구현을 위해서 Nginx 프록시 설정을 합니다. SSR 서버를 띄우는 부분은 #340 에 같이 올라갔습니다.

🙏 여기는 꼭 봐주세요! > 리뷰어가 특별히 봐주었으면 하는 부분이 있다면 작성해주세요

이해를 돕기 위해 포스팅을 작성했습니다.
https://hamo0.tistory.com/99 (비밀번호 1111, 성공하면 공개로 바꾸려고요....)

Summary by CodeRabbit

  • New Features
    • Enhanced real-time connection support for a smoother user experience.
    • Improved static content delivery with optimized caching for faster load times.
    • Implemented a proxy setup for better request handling and WebSocket support.

@hamo-o hamo-o added this to the 7️⃣ 7차 스프린트 milestone Mar 23, 2025
@hamo-o hamo-o self-assigned this Mar 23, 2025
@coderabbitai
Copy link

coderabbitai bot commented Mar 23, 2025

Walkthrough

The pull request updates the Nginx configuration in script/deploy/nginx/frontend.conf. It replaces the previous static file serving for the root location with a proxy setup that forwards requests to a local server on port 5173, including directives to support WebSockets and preserve the original host header. Additionally, static assets are now handled in a separate location block with defined caching policies and file handling rules.

Changes

File Path Summary of Changes
script/deploy/nginx/frontend.conf - Replaced root location configuration with proxying to localhost:5173.
- Added proxy directives: proxy_http_version, proxy_set_header Upgrade, Connection, Host, and proxy_cache_bypass.
- Introduced a new location block for static assets with caching (7 days expiration) and try_files directive for proper asset handling.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant Nginx
    participant Backend as Local Server (Port 5173)
    participant Static as Static Asset Handler (/var/www/html)

    Client->>Nginx: Send HTTP Request
    alt Request is for dynamic content
        Nginx->>Backend: Proxy request with WebSocket support
        Backend-->>Nginx: Processed Response
        Nginx-->>Client: Return Response
    else Request is for static content
        Nginx->>Static: Serve static asset from /var/www/html
        Static-->>Nginx: Asset content
        Nginx-->>Client: Return Static Content
    end
Loading

Suggested reviewers

  • dioo1461

Poem

I’m a little bunny, hopping with delight,
Nginx now dances to a brand new light.
Requests are forwarded with precision and cheer,
Static assets served without any fear.
WebSockets leap and hosts stand true—
A cheerful change from me to you! 🐇✨


🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai plan to trigger planning for file edits and PR creation.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@hamo-o hamo-o requested review from dioo1461, efdao and kwon204 March 23, 2025 22:21
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 9d3bedd and 424c0ad.

📒 Files selected for processing (1)
  • script/deploy/nginx/frontend.conf (2 hunks)
🔇 Additional comments (2)
script/deploy/nginx/frontend.conf (2)

37-42: Great implementation of Nginx reverse proxy for SSR!

The proxy setup is correctly configured to forward requests to your SSR server running locally on port 5173. The configuration includes all the necessary headers for WebSocket support (Upgrade and Connection: 'upgrade'), and preserves the original host header.


54-60:

Details

❓ Verification inconclusive

Revise the static file handling configuration.

The current configuration has a couple of potential issues:

  1. The try_files $uri /index.html; directive for static assets will cause 404 errors for missing static files to serve the index.html instead. This is typically not desired for static assets and could cause confusion.

  2. Consider adding the same security headers that are present in the root location.

        # 정적 assets
        location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg)$ {
            root /var/www/html;
            expires 7d;
            add_header Cache-Control "public, max-age=604800";
-            try_files $uri /index.html;
+            try_files $uri =404;
+            
+            # 보안 헤더 추가
+            add_header X-Content-Type-Options nosniff;
+            add_header X-Frame-Options SAMEORIGIN;
+            add_header X-XSS-Protection "1; mode=block";
        }

Does your frontend application need the fallback to index.html for static assets? If this is required for your application architecture, please clarify.


Attention: Confirm the static fallback behavior for missing assets

The updated configuration now returns a 404 for missing static files and adds security headers to align with your root settings. This helps avoid serving the index page as a fallback for missing assets—a behavior that is generally undesired for static resources. Please verify that your frontend application doesn't require the fallback to /index.html in this location; if it does for SPA routing or another purpose, indicate accordingly.

  • File affected: script/deploy/nginx/frontend.conf (Lines 54-60)
  • Changes made:
    • Replaced try_files $uri /index.html; with try_files $uri =404; to prevent serving the index page on 404 errors.
    • Added security headers:
      • add_header X-Content-Type-Options nosniff;
      • add_header X-Frame-Options SAMEORIGIN;
      • add_header X-XSS-Protection "1; mode=block";

If the SPA architectural requirements necessitate the fallback behavior, please clarify and adjust the configuration accordingly.

Copy link
Contributor

@dioo1461 dioo1461 left a comment

Choose a reason for hiding this comment

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

고생하셨습니다~

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (2)
script/deploy/nginx/frontend.conf (2)

51-52: Consider using a separate directory for static assets

The current configuration uses the same root directory (/var/www/html) for both the SSR application and static assets. Consider using a dedicated subdirectory for static assets (e.g., /var/www/html/assets or /var/www/html/static) to better organize your deployment and avoid potential conflicts.


51-51: Expand file type coverage for static assets

The current regex only covers common static files but misses some important web asset types like fonts (woff, woff2, ttf, eot), videos (mp4, webm), and documents (pdf). Consider expanding the file types to ensure comprehensive static asset handling.

- location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg)$ {
+ location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|eot|pdf|mp4|webm)$ {
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 424c0ad and b7e8ab9.

📒 Files selected for processing (1)
  • script/deploy/nginx/frontend.conf (1 hunks)
🧰 Additional context used
🧠 Learnings (1)
script/deploy/nginx/frontend.conf (1)
Learnt from: dioo1461
PR: softeer5th/Team4-enDolphin#350
File: script/deploy/nginx/frontend.conf:49-51
Timestamp: 2025-03-25T07:32:54.031Z
Learning: For Nginx configurations with SSR (Server-Side Rendering), caching directives like 'expires' and 'Cache-Control' headers should be removed from proxy location blocks to prevent API requests from being cached by browsers. Static assets should have their own location blocks with appropriate caching settings.
🔇 Additional comments (1)
script/deploy/nginx/frontend.conf (1)

37-42: Well-implemented proxy configuration for SSR

The proxy configuration for the SSR server is correctly implemented with essential headers for WebSocket support and proper host header forwarding. Good job avoiding caching directives in this proxy block, which aligns with the best practices for SSR implementations to prevent unintended caching of dynamic content and API requests.

root /var/www/html;
expires 7d;
add_header Cache-Control "public, max-age=604800";
try_files $uri /index.html;
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Reconsider fallback behavior for static assets

The try_files $uri /index.html; directive will serve the index.html file when a static asset is not found. This could cause confusing behavior for missing assets and potentially hide 404 errors. For static assets, it's generally better to return a 404 status when the file is not found.

- try_files $uri /index.html;
+ try_files $uri =404;
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
try_files $uri /index.html;
try_files $uri =404;

@hamo-o hamo-o merged commit 1a86387 into dev Mar 27, 2025
1 check passed
@hamo-o hamo-o deleted the feature/all/ssr-script branch March 27, 2025 07:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants