Skip to content

Conversation

@GaoNeng-wWw
Copy link
Collaborator

@GaoNeng-wWw GaoNeng-wWw commented Nov 30, 2025

PR

PR Checklist

Please check if your PR fulfills the following requirements:

  • The commit message follows our Commit Message Guidelines
  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been added / updated (for bug fixes / features)

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Documentation content changes
  • Other... Please describe:

What is the current behavior?

用户必须注释 RejectRequestGuard 才可以禁用演示模式

Issue Number: N/A

What is the new behavior?

用户只需要配置 PREVIEW_MODE=true/false 即可以在运行时动态开启是否使用演示模式。如果为true,那么后端命令行会有相关提示

image

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

Summary by CodeRabbit

Release Notes

  • New Features

    • Introduced PREVIEW_MODE configuration setting (enabled by default) to control application preview and demonstration features
    • Startup notifications alert users when running in preview mode, including instructions to disable it
  • Documentation

    • Updated environment configuration documentation with new PREVIEW_MODE environment variable

✏️ Tip: You can customize this high-level summary in your review settings.

@github-actions github-actions bot added the enhancement New feature or request label Nov 30, 2025
@coderabbitai
Copy link

coderabbitai bot commented Nov 30, 2025

Walkthrough

Introduces a PREVIEW_MODE configuration flag to control preview/demonstration behavior. When enabled (default), logs startup warnings. When disabled, bypasses request rejection logic in the guard. Configuration defined in schema, environment example, and utilized across app lifecycle.

Changes

Cohort / File(s) Summary
Configuration Definition
template/nestJs/src/config-schema.ts
Added PREVIEW_MODE boolean field to Configure type and schema with Joi validation; defaults to true
Environment & Documentation
template/nestJs/.env.example, docs/tiny-pro-backend-dev-guideline.md
Added PREVIEW_MODE environment variable and configuration reference to development guidelines
Feature Flag Implementation
template/nestJs/src/app.module.ts
Injects ConfigService, checks PREVIEW_MODE at module initialization, emits warning logs when enabled to inform about demo mode
Request Guard Gating
template/nestJs/src/public/reject.guard.ts
Injects ConfigService, skips rejection logic when PREVIEW_MODE is disabled; existing rejection behavior preserved when enabled

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

  • Configuration pattern is consistent across schema, environment, and documentation files
  • Feature flag implementation follows standard conditional checks with no complex logic
  • Constructor injections are straightforward dependency additions
  • No external dependencies or side effects beyond conditional branching

Poem

🐰 A flag takes flight, preview mode in sight,
Guard gates now open when demo's delight!
Warnings echo soft, warnings echo clear,
Config whispers true, the preview mode is here! ✨

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'feat(nest.js): add preview mode flag' directly and accurately summarizes the main change—introducing a PREVIEW_MODE configuration flag across the Nest.js application.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • 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

Comment @coderabbitai help to get the list of available commands and usage tips.

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)
template/nestJs/.env.example (1)

20-21: Env example for PREVIEW_MODE is clear; linter ordering warning is optional

The new PREVIEW_MODE=true example with the Chinese comment is clear and matches the feature semantics. The dotenv-linter “UnorderedKey” warning about key order is non-functional; you can either ignore it or move PREVIEW_MODE to satisfy whatever ordering convention you prefer.

docs/tiny-pro-backend-dev-guideline.md (1)

46-47: Docs update correctly documents PREVIEW_MODE

The added PREVIEW_MODE lines in the sample .env block are consistent with the template file. You might optionally extend the comment to say that it defaults to true and setting it to false disables demo/preview mode, but it’s already understandable as-is.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c30341b and 4f882a6.

📒 Files selected for processing (5)
  • docs/tiny-pro-backend-dev-guideline.md (1 hunks)
  • template/nestJs/.env.example (1 hunks)
  • template/nestJs/src/app.module.ts (2 hunks)
  • template/nestJs/src/config-schema.ts (2 hunks)
  • template/nestJs/src/public/reject.guard.ts (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (2)
template/nestJs/src/app.module.ts (1)
template/nestJs/src/config-schema.ts (1)
  • Configure (3-23)
template/nestJs/src/public/reject.guard.ts (1)
template/nestJs/src/config-schema.ts (1)
  • Configure (3-23)
🪛 dotenv-linter (4.0.0)
template/nestJs/.env.example

[warning] 21-21: [UnorderedKey] The PREVIEW_MODE key should go before the REDIS_HOST key

(UnorderedKey)

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: e2e-test
🔇 Additional comments (3)
template/nestJs/src/config-schema.ts (1)

22-45: PREVIEW_MODE added cleanly to typed config and Joi schema

PREVIEW_MODE: boolean in Configure and Joi.bool().default(true) are consistent and align with the intended default-on demo mode. This should work smoothly with ConfigService<Configure> usage elsewhere.

template/nestJs/src/app.module.ts (1)

40-40: Typed config integration for PREVIEW_MODE is sound

Importing CONFIG_SCHEMA and injecting ConfigService<Configure> into AppModule ties together the Joi schema and runtime access nicely, and keeps this.cfg.get('PREVIEW_MODE') strongly typed.

Also applies to: 93-94

template/nestJs/src/public/reject.guard.ts (1)

11-24: Guard-level PREVIEW_MODE check correctly gates demo-mode behavior

Injecting ConfigService<Configure> and short-circuiting canActivate when PREVIEW_MODE is false cleanly disables the rejection behavior without needing to remove the APP_GUARD. When PREVIEW_MODE is true, existing i18n-based rejection logic is preserved for handlers/classes marked with the reject metadata.

Comment on lines +101 to +106
const IS_PREVIEW_MOD = this.cfg.get('PREVIEW_MODE');
if (IS_PREVIEW_MOD) {
Logger.warn('You are currently in demonstration mode. All additions, deletions, and modifications request will be rejected');
Logger.warn('If you want to disable the demo mode, please set the `PREVIEW_MODE` environment variable to `false`')
Logger.warn('Alternatively, you can create an `.env` file and set `PREVIEV_MODE` to `false`')
}
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

cat -n template/nestJs/src/app.module.ts | sed -n '95,110p'

Repository: opentiny/tiny-pro

Length of output: 178


🏁 Script executed:

rg "PREVIEV_MODE|PREVIEW_MODE" template/nestJs/src/app.module.ts -n

Repository: opentiny/tiny-pro

Length of output: 178


🏁 Script executed:

rg "PREVIEV_MODE" . --type ts --type js -n

Repository: opentiny/tiny-pro

Length of output: 178


Fix PREVIEV_MODE typo in demo-mode warning message

Line 105 contains a typo that will mislead users. The warning tells users to set PREVIEV_MODE to disable demo mode, but the actual environment variable is PREVIEW_MODE. Users following this instruction will set the wrong variable and remain stuck in demo mode.

Apply this fix:

-      Logger.warn('Alternatively, you can create an `.env` file and set `PREVIEV_MODE` to `false`')
+      Logger.warn('Alternatively, you can create an `.env` file and set `PREVIEW_MODE` to `false`')

Consider also updating "modification request" to "modification requests" on line 103 for grammatical consistency.

📝 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
const IS_PREVIEW_MOD = this.cfg.get('PREVIEW_MODE');
if (IS_PREVIEW_MOD) {
Logger.warn('You are currently in demonstration mode. All additions, deletions, and modifications request will be rejected');
Logger.warn('If you want to disable the demo mode, please set the `PREVIEW_MODE` environment variable to `false`')
Logger.warn('Alternatively, you can create an `.env` file and set `PREVIEV_MODE` to `false`')
}
const IS_PREVIEW_MOD = this.cfg.get('PREVIEW_MODE');
if (IS_PREVIEW_MOD) {
Logger.warn('You are currently in demonstration mode. All additions, deletions, and modifications request will be rejected');
Logger.warn('If you want to disable the demo mode, please set the `PREVIEW_MODE` environment variable to `false`')
Logger.warn('Alternatively, you can create an `.env` file and set `PREVIEW_MODE` to `false`')
}
🤖 Prompt for AI Agents
In template/nestJs/src/app.module.ts around lines 101 to 106, the third
Logger.warn message contains a typo "PREVIEV_MODE" which misleads users — change
it to the correct environment variable name "PREVIEW_MODE"; also adjust the
first warning text on line ~103 from "modification request" to "modification
requests" for grammatical consistency; make sure both Logger.warn lines reflect
the corrected variable name and pluralized wording exactly.

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

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant