这是indexloc提供的服务,不要输入任何密码
Skip to content

Conversation

@virajago
Copy link

@virajago virajago commented Nov 8, 2025

Summary

  • Fix ENOENT error when running npm run dev in development mode
  • Update server to only serve static files in production mode
  • Add TypeScript configuration for react-scripts compatibility

Changes

  1. server/index.ts: Add environment check to conditionally serve static files only in production
  2. client/tsconfig.json: Add allowJs and noFallthroughCasesInSwitch compiler options
  3. client/src/react-app-env.d.ts: Add TypeScript declaration file for react-scripts

Test plan

  • Run npm run dev successfully without ENOENT errors
  • Verify backend API runs on port 8081
  • Verify React dev server runs on port 3000
  • Confirm API endpoints are accessible

Notes

Local developers need to add DANGEROUSLY_DISABLE_HOST_CHECK=true to client/.env to bypass webpack dev server host validation (not included in this PR as .env files are gitignored).

Update server to only serve static files in production mode, preventing ENOENT errors when client/build doesn't exist during development. Add TypeScript configuration updates for react-scripts compatibility.

Note: Local developers need to add DANGEROUSLY_DISABLE_HOST_CHECK=true to client/.env to bypass webpack dev server host validation.
@virajago virajago requested a review from a team as a code owner November 8, 2025 10:56
@gemini-code-assist
Copy link

Summary of Changes

Hello @virajago, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly improves the local development experience by resolving critical npm run dev errors and streamlining the server's static file handling. It ensures that the backend correctly distinguishes between development and production environments for serving client assets, while also enhancing TypeScript configuration for better compatibility with React development tools.

Highlights

  • Local Development Fixes: Resolves ENOENT errors encountered when running npm run dev for local development, making the development environment functional.
  • Environment-Specific Static File Serving: Modifies the server to conditionally serve static files only in production environments, preventing conflicts and ensuring the React development server handles assets during development.
  • TypeScript Configuration Enhancements: Updates tsconfig.json with allowJs and noFallthroughCasesInSwitch options and adds react-app-env.d.ts for better react-scripts compatibility and stricter type checking.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request fixes errors for local development by conditionally serving static files only in production and updating TypeScript configurations. The changes are generally good, but I've identified a potential issue in how the environment is checked for serving static files. My suggestion aims to make this check more robust to prevent crashes in different environments.

Comment on lines +292 to +325
const isDevelopment = process.env.NODE_ENV === "development";

if (!isDevelopment) {
const buildPath = path.join(__dirname, "../client/build");

const setCustomCacheControl = (res: Response, filePath: string) => {
// For HTML files, always revalidate to get the latest version
if (path.extname(filePath) === ".html") {
res.setHeader("Cache-Control", "no-cache, must-revalidate");
} else {
// For all other static assets (JS, CSS, images), cache for a long time
res.setHeader("Cache-Control", "public, max-age=31536000, immutable");
}
};

// Catch-all handler for React routing
app.get("*", (req: Request, res: Response) => {
const indexPath = path.join(buildPath, "index.html");
res.setHeader(
"Cache-Control",
"no-store, no-cache, must-revalidate, proxy-revalidate"
app.use(
express.static(buildPath, {
setHeaders: setCustomCacheControl,
etag: true,
})
);
res.sendFile(indexPath);
});

// Catch-all handler for React routing
app.get("*", (req: Request, res: Response) => {
const indexPath = path.join(buildPath, "index.html");
res.setHeader(
"Cache-Control",
"no-store, no-cache, must-revalidate, proxy-revalidate"
);
res.sendFile(indexPath);
});
} else {
logger.info("Development mode: static files will be served by webpack-dev-server on port 3000");
}

Choose a reason for hiding this comment

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

high

The current logic for serving static files is based on NODE_ENV not being 'development'. This can cause the server to crash with an ENOENT error if NODE_ENV is not set, or if it's set to another non-production value like 'test', because it will try to serve files from a build directory that doesn't exist.

A more robust approach is to explicitly check for 'production' to serve static files, and 'development' to log the info message. This makes the behavior predictable across all environments and prevents crashes when NODE_ENV is not set.

  if (process.env.NODE_ENV === "production") {
    const buildPath = path.join(__dirname, "../client/build");

    const setCustomCacheControl = (res: Response, filePath: string) => {
      // For HTML files, always revalidate to get the latest version
      if (path.extname(filePath) === ".html") {
        res.setHeader("Cache-Control", "no-cache, must-revalidate");
      } else {
        // For all other static assets (JS, CSS, images), cache for a long time
        res.setHeader("Cache-Control", "public, max-age=31536000, immutable");
      }
    };

    app.use(
      express.static(buildPath, {
        setHeaders: setCustomCacheControl,
        etag: true,
      })
    );

    // Catch-all handler for React routing
    app.get("*", (req: Request, res: Response) => {
      const indexPath = path.join(buildPath, "index.html");
      res.setHeader(
        "Cache-Control",
        "no-store, no-cache, must-revalidate, proxy-revalidate"
      );
      res.sendFile(indexPath);
    });
  } else if (process.env.NODE_ENV === "development") {
    logger.info("Development mode: static files will be served by webpack-dev-server on port 3000");
  }

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant