-
Notifications
You must be signed in to change notification settings - Fork 18
feat(nest.js): add preview mode flag #143
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dev
Are you sure you want to change the base?
feat(nest.js): add preview mode flag #143
Conversation
WalkthroughIntroduces 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
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes
Poem
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this 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 optionalThe new
PREVIEW_MODE=trueexample 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 movePREVIEW_MODEto satisfy whatever ordering convention you prefer.docs/tiny-pro-backend-dev-guideline.md (1)
46-47: Docs update correctly documents PREVIEW_MODEThe added
PREVIEW_MODElines in the sample.envblock are consistent with the template file. You might optionally extend the comment to say that it defaults totrueand setting it tofalsedisables demo/preview mode, but it’s already understandable as-is.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 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: booleaninConfigureandJoi.bool().default(true)are consistent and align with the intended default-on demo mode. This should work smoothly withConfigService<Configure>usage elsewhere.template/nestJs/src/app.module.ts (1)
40-40: Typed config integration for PREVIEW_MODE is soundImporting
CONFIG_SCHEMAand injectingConfigService<Configure>intoAppModuleties together the Joi schema and runtime access nicely, and keepsthis.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 behaviorInjecting
ConfigService<Configure>and short-circuitingcanActivatewhenPREVIEW_MODEis false cleanly disables the rejection behavior without needing to remove theAPP_GUARD. WhenPREVIEW_MODEis true, existing i18n-based rejection logic is preserved for handlers/classes marked with therejectmetadata.
| 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`') | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 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 -nRepository: opentiny/tiny-pro
Length of output: 178
🏁 Script executed:
rg "PREVIEV_MODE" . --type ts --type js -nRepository: 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.
| 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.
PR
PR Checklist
Please check if your PR fulfills the following requirements:
PR Type
What kind of change does this PR introduce?
What is the current behavior?
用户必须注释
RejectRequestGuard才可以禁用演示模式Issue Number: N/A
What is the new behavior?
用户只需要配置
PREVIEW_MODE=true/false即可以在运行时动态开启是否使用演示模式。如果为true,那么后端命令行会有相关提示Does this PR introduce a breaking change?
Other information
Summary by CodeRabbit
Release Notes
New Features
Documentation
✏️ Tip: You can customize this high-level summary in your review settings.