-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from perseidesjs/release-2-0-0
chore: Update rate limit middleware and documentation
- Loading branch information
Showing
9 changed files
with
106 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,4 +14,5 @@ bun.lockb | |
/subscribers | ||
/__mocks__ | ||
|
||
tsconfig.tsbuildinfo | ||
tsconfig.tsbuildinfo | ||
tsconfig.build.tsbuildinfo |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
export { defaultRateLimit } from './api/middlewares/default-rate-limit' | ||
export { configureDefaults } from './utils/configure-defaults' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { type PluginOptions } from '../constants' | ||
import { configManager } from './global-configuration' | ||
|
||
export function configureDefaults(options: Partial<PluginOptions>): void { | ||
configManager.setConfig(options) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { type PluginOptions } from '../constants' | ||
import { configManager } from './global-configuration' | ||
|
||
export function getDefaultOptions(): PluginOptions { | ||
const globalConfig = configManager.getConfig() | ||
|
||
return { | ||
limit: globalConfig.limit, | ||
window: globalConfig.window, | ||
includeHeaders: globalConfig.includeHeaders, | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { type PluginOptions } from '../constants' | ||
|
||
class ConfigurationManager { | ||
private static instance: ConfigurationManager | ||
private config: PluginOptions | ||
|
||
private constructor() { | ||
this.config = { | ||
limit: 5, | ||
window: 60, | ||
includeHeaders: true | ||
} | ||
} | ||
|
||
public static getInstance(): ConfigurationManager { | ||
if (!ConfigurationManager.instance) { | ||
ConfigurationManager.instance = new ConfigurationManager() | ||
} | ||
return ConfigurationManager.instance | ||
} | ||
|
||
public setConfig(options: Partial<PluginOptions>): void { | ||
this.config = { | ||
...this.config, | ||
...options | ||
} | ||
} | ||
|
||
public getConfig(): PluginOptions { | ||
return { ...this.config } | ||
} | ||
} | ||
|
||
export const configManager = ConfigurationManager.getInstance() |