Skip to content

Conversation

gediminasel
Copy link

Fixes #5642 and makes npx and pnpx work for @actual/sync-server

@gediminasel gediminasel requested a review from matt-fidd as a code owner August 28, 2025 22:04
@actual-github-bot actual-github-bot bot changed the title [fix] Support webRoot being in hidden folder (e.g. .cache) [WIP] [fix] Support webRoot being in hidden folder (e.g. .cache) Aug 28, 2025
Copy link

netlify bot commented Aug 28, 2025

Deploy Preview for actualbudget ready!

Name Link
🔨 Latest commit 6e53b69
🔍 Latest deploy log https://app.netlify.com/projects/actualbudget/deploys/68b0d6f4c54d360008539766
😎 Deploy Preview https://deploy-preview-5643.demo.actualbudget.org
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@matt-fidd matt-fidd added this to the v25.9.0 milestone Aug 28, 2025
@gediminasel gediminasel force-pushed the master branch 2 times, most recently from 64b337a to ee6f926 Compare August 28, 2025 22:21
Fixes actualbudget#5642 and makes npx and pnpx work for @actual/sync-server
@gediminasel gediminasel changed the title [WIP] [fix] Support webRoot being in hidden folder (e.g. .cache) [WIP] [fix] Support webRoot being in a hidden folder (e.g. .cache) Aug 28, 2025
@matt-fidd
Copy link
Member

Hey @gediminasel if this is ready for review please could you remove the [WIP ] prefix from the title? It would be nice to get this in before the v25.10 release

@gediminasel gediminasel changed the title [WIP] [fix] Support webRoot being in a hidden folder (e.g. .cache) [fix] Support webRoot being in a hidden folder (e.g. .cache) Aug 29, 2025
Copy link
Contributor

coderabbitai bot commented Aug 29, 2025

Walkthrough

In production mode within packages/sync-server/src/app.ts, the code serving the frontend changed from sending a concatenated file path to using res.sendFile with a filename and a root option: res.sendFile('index.html', { root: config.get('webRoot') }). No other logic or public interfaces were modified.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Assessment against linked issues

Objective Addressed Explanation
Serve the root path with index.html without NotFoundError when running via npx/pnpx in production ([#5642])

Tip

🔌 Remote MCP (Model Context Protocol) integration is now available!

Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats.


📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 23f1bae and 6e53b69.

⛔ Files ignored due to path filters (1)
  • upcoming-release-notes/5643.md is excluded by !**/*.md
📒 Files selected for processing (1)
  • packages/sync-server/src/app.ts (1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
**/*.{ts,tsx}

📄 CodeRabbit inference engine (.cursor/rules/typescript.mdc)

**/*.{ts,tsx}: Write concise, technical TypeScript code
Use functional and declarative programming patterns; avoid classes
Prefer iteration and modularization over code duplication
Use descriptive variable names with auxiliary verbs (e.g., isLoaded, hasError)
Structure files with sections in order: exported page/component, GraphQL queries, helpers, static content, types
Favor named exports for components and utilities
Prefer interfaces over types in TypeScript
Avoid enums; use objects or maps instead
Avoid using any or unknown unless absolutely necessary; prefer existing types
Avoid type assertions with as or non-null !; prefer satisfies
Use the function keyword for pure functions
Avoid unnecessary curly braces in conditionals; use concise syntax for simple statements

Files:

  • packages/sync-server/src/app.ts
🧠 Learnings (1)
📓 Common learnings
Learnt from: tlesicka
PR: actualbudget/actual#3689
File: packages/loot-core/src/platform/server/fs/index.web.ts:319-340
Timestamp: 2024-10-25T05:04:40.902Z
Learning: In `packages/loot-core/src/platform/server/fs/index.web.ts`, errors are already handled in other locations, so additional error handling in `copyFile` is unnecessary.
🔇 Additional comments (1)
packages/sync-server/src/app.ts (1)

146-149: Verify SPA fallback under hidden webRoot
Using sendFile('index.html', { root }) bypasses Express’ hidden-path check (/.…), preventing 404s when webRoot lives in a dot directory. Refactor to resolve and reuse webRoot:

   console.log('Running in production mode - Serving static React app');

   const webRoot = resolve(config.get('webRoot'));
   app.use(express.static(webRoot, { index: false }));
   app.get('/{*splat}', (req, res) =>
     res.sendFile('index.html', { root: webRoot }),
   );

Rerun on Linux with XDG_CACHE_HOME=$HOME/.cache:

#!/bin/bash
set -euo pipefail
export XDG_CACHE_HOME="$HOME/.cache"
PORT=5006
pnpx -y @actual-app/sync-server --port "$PORT" >/tmp/actual-sync.log 2>&1 &
pid=$!
sleep 2
for path in "/" "/anything/that/should/spa"; do
  code=$(curl -s -o /dev/null -w "%{http_code}" "http://localhost:$PORT$path")
  echo "$path -> $code"
done
kill "$pid"

Confirm both / and nested routes return 200.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 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.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbit in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbit 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:
    • @coderabbit gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbit read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbit help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbit ignore or @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbit summary or @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbit or @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

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • 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.

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

Successfully merging this pull request may close these issues.

[Bug]: npx @actual-app/sync-server doesn't serve http page (NotFoundError)
2 participants