Skip to content

Add option to programmatically disable plugin#11

Open
Abion47 wants to merge 1 commit intotobias-kaerst-software:mainfrom
Abion47:main
Open

Add option to programmatically disable plugin#11
Abion47 wants to merge 1 commit intotobias-kaerst-software:mainfrom
Abion47:main

Conversation

@Abion47
Copy link

@Abion47 Abion47 commented Jan 8, 2026

The idiomatic way to disable plugins in Elysia is with an enabled property on the configuration object. This will allow an easy and idiomatic way to programmatically disable the plugin, such as in non-production environments or when the plugin is misbehaving.

Summary by CodeRabbit

  • New Features
    • Added an optional setting to disable helmet security headers when initializing the service.

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

@coderabbitai
Copy link

coderabbitai bot commented Jan 8, 2026

📝 Walkthrough

Walkthrough

The changes introduce an optional enabled flag to the HelmetOptions type and implement conditional middleware initialization in the main export. When the flag is explicitly set to false, the helmet middleware is bypassed entirely, returning a minimal Elysia instance without helmet header setup.

Changes

Cohort / File(s) Summary
Type Definition
src/helmet.ts
Added optional enabled?: boolean property to HelmetOptions type for toggling middleware activation
Conditional Middleware Logic
src/index.ts
Added early return when options.enabled is false, skipping helmet middleware and onRequest hook registration; otherwise retains existing behavior

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 A flag now guards the helmet's gate,
When false, we skip and thus deflate,
The headers rest, the choice is ours,
To shield or not with security's powers! 🛡️✨

🚥 Pre-merge checks | ✅ 3
✅ 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 'Add option to programmatically disable plugin' directly and clearly summarizes the main change: adding an enabled property to disable the plugin programmatically.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

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: 0

🧹 Nitpick comments (1)
src/index.ts (1)

6-9: Consider including the aot option for consistency.

The disabled path includes seed but omits aot, while the enabled path (lines 11-14) includes both. For consistency and to avoid potential confusion, consider including the aot option here as well.

♻️ Proposed change for consistency
   if (options.enabled === false) {
     return new Elysia({
       name: 'elysia-helmet',
       seed: options.seed ?? '',
+      aot: options.aot ?? true,
     });
   }
📜 Review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 24d91af and 3e2dfef.

📒 Files selected for processing (2)
  • src/helmet.ts
  • src/index.ts
🔇 Additional comments (2)
src/helmet.ts (1)

46-46: LGTM!

The optional enabled property is correctly typed and positioned. The property provides a clean, idiomatic way to disable the plugin programmatically.

src/index.ts (1)

5-10: Correct implementation of the disable feature.

The explicit === false check correctly handles all cases:

  • undefined or true → plugin enabled (default behavior maintained)
  • false → plugin disabled (new behavior)

This approach properly maintains backward compatibility while adding the new disable functionality.

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