Skip to content

Fixed: frontend could not correctly detect changes when the backend port was modified (#37)#38

Open
r404r wants to merge 13 commits intoAnionex:mainfrom
r404r:fix/20261213-port
Open

Fixed: frontend could not correctly detect changes when the backend port was modified (#37)#38
r404r wants to merge 13 commits intoAnionex:mainfrom
r404r:fix/20261213-port

Conversation

@r404r
Copy link
Contributor

@r404r r404r commented Dec 13, 2025

Try to fixit.
Now vite.config.ts can correctly read the PORT environment variable from the .env file.

Root cause: Using process.env.PORT could not obtain variables from the .env file, because when the Vite config file runs, it does not automatically load .env into process.env.

Fixes made:

  1. Used Vite’s loadEnv function to manually load environment variables.
  2. Added the @types/node dependency to support Node.js module types.
  3. Added "types": ["node"] in tsconfig.node.json.

Verification shows that PORT=5080 has been correctly read, and the frontend proxy now correctly points to http://localhost:5080.

Anionex and others added 13 commits December 11, 2025 16:58
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
# Conflicts:
#	.env.example
#	backend/config.py
The issue has been fixed!

`vite.config.ts` can correctly read the `PORT` environment variable from the `.env` file.

**Root cause**: Using `process.env.PORT` could not obtain variables from the `.env` file, because when the Vite config file runs, it does not automatically load `.env` into `process.env`.

**Fixes made**:
1. Used Vite’s `loadEnv` function to manually load environment variables.
2. Added the `@types/node` dependency to support Node.js module types.
3. Added `"types": ["node"]` in `tsconfig.node.json`.

Verification shows that `PORT=5080` has been correctly read, and the frontend proxy now correctly points to `http://localhost:5080`.
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @r404r, 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 primarily resolves a critical issue where the frontend failed to correctly read the backend port from .env files, leading to potential misconfigurations in development environments. The fix involves explicitly loading environment variables within Vite's configuration. Additionally, it introduces a new site status feature, comprising a backend endpoint and interactive frontend components, to enhance transparency regarding the application's operational state and offer a sponsorship mechanism. A minor update to an AI image generation model is also included.

Highlights

  • Frontend Environment Variable Handling: Corrected the frontend's ability to detect and use the PORT environment variable from .env files by implementing Vite's loadEnv function, ensuring proper backend proxy configuration.
  • Node.js Type Support: Added @types/node dependency and configured tsconfig.node.json to support Node.js module types, resolving type-related issues in the Vite configuration.
  • Site Status Feature: Introduced a new backend API endpoint /api/site-status and corresponding frontend components (SiteStatusBanner, SponsorModal) to display and manage the application's operational status and provide sponsorship options.
  • AI Model Update: Updated the default model for OpenAIImageProvider from 'gemini-3-pro-image-preview' to 'gemini-3-pro' in the backend.
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
Contributor

@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 successfully addresses the issue where the frontend failed to detect backend port changes by correctly implementing loadEnv in the Vite configuration. The changes to vite.config.ts and tsconfig.node.json are appropriate and follow best practices for an ES module environment.

In addition to the bug fix, this PR introduces a new site status banner and a sponsorship modal. This is a nice enhancement for communicating the application's operational status to users.

I've identified a few areas for improvement, primarily related to the new status feature. There are potential crash scenarios on the frontend if the backend provides an unexpected status value. I've added comments with suggestions to add validation on both the backend and frontend to make the feature more robust. I also found some minor issues with hardcoded values and incorrect CSS classes in the new components. Please see the detailed comments for suggestions.

获取站点状态
可选值: sufficient (余额充足), insufficient (欠费), maintenance (维护)
"""
status = os.getenv('SITE_STATUS', 'sufficient')
Copy link
Contributor

Choose a reason for hiding this comment

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

high

The site_status endpoint reads the SITE_STATUS environment variable but doesn't validate its value. If an unexpected value (e.g., a typo like 'maintenence') is set in the environment, it will be passed to the frontend. This could cause the SiteStatusBanner component to crash, as it only expects 'sufficient', 'insufficient', or 'maintenance'. To make the API more robust, you should validate the status and default to a safe value if it's invalid.

Suggested change
status = os.getenv('SITE_STATUS', 'sufficient')
ALLOWED_STATUSES = {'sufficient', 'insufficient', 'maintenance'}
status = os.getenv('SITE_STATUS', 'sufficient')
if status not in ALLOWED_STATUSES:
status = 'sufficient'

},
};

const config = statusConfig[status];
Copy link
Contributor

Choose a reason for hiding this comment

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

high

The component will crash if it receives an unexpected status from the API (e.g., a typo or a new status not yet handled). The expression statusConfig[status] would be undefined, leading to a TypeError when trying to access properties like bgColor. To make the component more resilient, you should handle unknown statuses by providing a safe fallback, such as the 'sufficient' state configuration.

Suggested change
const config = statusConfig[status];
const config = statusConfig[status] || statusConfig.sufficient;

Comment on lines +37 to +110
const statusConfig = {
sufficient: {
icon: <CheckCircle className="w-5 h-5 flex-shrink-0" />,
bgColor: 'bg-green-50',
borderColor: 'border-green-200',
textColor: 'text-green-900',
iconColor: 'text-green-500',
title: '✅ 站点运行正常',
message: (
<>
本站点由作者完全自费支持运营,当前运行正常。
<br />
如有疑问或合作意向,欢迎联系:
<a
href="mailto:1005128408@qq.com"
className="font-semibold underline hover:text-green-700 transition-colors ml-1"
>
1005128408@qq.com
</a>
</>
),
},
insufficient: {
icon: <AlertCircle className="w-5 h-5 flex-shrink-0" />,
bgColor: 'bg-orange-50',
borderColor: 'border-orange-200',
textColor: 'text-orange-900',
iconColor: 'text-orange-500',
title: '⚠️ 站点余额不足,可能影响功能使用',
message: (
<>
本站点由作者完全自费支持运营,余额可能会间歇性见底,会尽快补充余额。
<br />
也欢迎
<button
onClick={() => setIsSponsorModalOpen(true)}
className="font-semibold underline hover:text-orange-700 transition-colors mx-1"
>
打赏作者
</button>
,我会将其全部用于站点维护🚀
<br />
如有疑问或合作意向,欢迎联系:
<a
href="mailto:1005128408@qq.com"
className="font-semibold underline hover:text-orange-700 transition-colors ml-1"
>
1005128408@qq.com
</a>
</>
),
},
maintenance: {
icon: <Wrench className="w-5 h-5 flex-shrink-0" />,
bgColor: 'bg-blue-50',
borderColor: 'border-blue-200',
textColor: 'text-blue-900',
iconColor: 'text-blue-500',
title: '🔧 系统维护中',
message: (
<>
站点正在进行系统维护,部分功能可能暂时不可用。感谢您的理解与支持!
<br />
如有疑问,请联系:
<a
href="mailto:1005128408@qq.com"
className="font-semibold underline hover:text-blue-700 transition-colors ml-1"
>
1005128408@qq.com
</a>
</>
),
},
};
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

The contact email address 1005128408@qq.com is hardcoded in three separate places within the statusConfig object. This makes it difficult to update and increases the risk of inconsistency. It would be better to define this email as a constant at the top of the file and reference it within the component. This improves maintainability.

For example:

const CONTACT_EMAIL = "1005128408@qq.com";

export const SiteStatusBanner: React.FC<SiteStatusBannerProps> = ({ className = '' }) => {
  // ...
  const statusConfig = {
    sufficient: {
      // ...
      message: (
        <>
          {/* ... */}
          <a 
            href={`mailto:${CONTACT_EMAIL}`}
            className="..."
          >
            {CONTACT_EMAIL}
          </a>
        </>
      ),
    },
    // ...etc
  };
  // ...
};

Comment on lines +35 to +39
<p className="text-sm md:text-base text-black-600 leading-relaxed">
项目目前完全由作者自费, <br />
如果这个项目对您有帮助,<br />
欢迎请开发者喝杯咖啡 ☕
</p>
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

The Tailwind CSS class text-black-600 is likely incorrect. By default, Tailwind CSS does not provide shades for the color black (e.g., black-600). This style will probably not be applied. For consistency with other components in the app, you should use a shade of gray, such as text-gray-600.

Suggested change
<p className="text-sm md:text-base text-black-600 leading-relaxed">
项目目前完全由作者自费, <br />
如果这个项目对您有帮助,<br />
欢迎请开发者喝杯咖啡
</p>
<p className="text-sm md:text-base text-gray-600 leading-relaxed">
项目目前完全由作者自费, <br />
如果这个项目对您有帮助,<br />
欢迎请开发者喝杯咖啡
</p>

Comment on lines +57 to +59
<p className="text-l text-black-500 pt-2">
扫码赞赏任意金额,感谢您的支持 ❤️
</p>
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

There are two issues with the CSS classes on this line:

  1. text-l is not a valid Tailwind CSS class for font size. The correct class for 'large' is text-lg.
  2. text-black-500 is also likely incorrect, as Tailwind doesn't provide shades for black by default. It should probably be text-gray-500 to maintain consistency with the rest of the application's styling.
Suggested change
<p className="text-l text-black-500 pt-2">
扫码赞赏任意金额,感谢您的支持 ❤️
</p>
<p className="text-lg text-gray-500 pt-2">
扫码赞赏任意金额,感谢您的支持 ❤️
</p>

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.

2 participants