-
-
Notifications
You must be signed in to change notification settings - Fork 9
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 #32 from medishen/dev/v2
refactor(config): Config and settings are refactored and each section is divided into separate modules and global is used instead of settings.
- Loading branch information
Showing
20 changed files
with
513 additions
and
155 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,2 +1,20 @@ | ||
// Express-style special symbol for default trust proxy behavior | ||
export const TRUST_PROXY_DEFAULT_SYMBOL = '@@symbol:trust_proxy_default'; | ||
export const CORS_METADATA = { | ||
CORS_WATERMARK: 'cors:watermark', | ||
}; | ||
export const VIEWS_METADATA = { | ||
VIEWS_WATERMARK: 'cors:watermark', | ||
}; | ||
export const PROXY_METADATA = { | ||
PROXY_WATERMARK: 'proxy:watermark', | ||
}; | ||
export const COOKIES_METADATA = { | ||
COOKIES_WATERMARK: 'cookies:watermark', | ||
}; | ||
export const CACHE_METADATA = { | ||
CACHE_WATERMARK: 'cache:watermark', | ||
}; | ||
export const GLOBAL_METADATA = { | ||
GLOBAL_WATERMARK: 'global:watermark', | ||
}; |
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,4 @@ | ||
export * from './config-module'; | ||
export * from './services'; | ||
export * from './modules'; | ||
export * from './types/config.types'; | ||
export * from './interface/config.interface'; |
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,50 +1,28 @@ | ||
import { CorsOptions, Environment, EtagIdentifier, TtlIdentifier } from '@gland/common'; | ||
import { Environment, EtagIdentifier, TtlIdentifier } from '@gland/common'; | ||
import { TrustProxyOption } from '../types/config.types'; | ||
export interface CookieConfig { | ||
|
||
export interface ProxyServiceConfig { | ||
trustProxy?: TrustProxyOption; | ||
proxyTrustCount?: number; | ||
proxyIpHeader?: string; | ||
} | ||
|
||
export interface CookieOptions { | ||
secure?: boolean; | ||
httpOnly?: boolean; | ||
sameSite?: 'Strict' | 'Lax' | 'None'; | ||
domain?: string; | ||
path?: string; | ||
maxAge?: number; | ||
} | ||
export interface IConfigSettings { | ||
etag?: EtagIdentifier; | ||
subdomainOffset?: number; | ||
|
||
maxIpsCount?: number; | ||
|
||
poweredBy?: string | boolean; | ||
|
||
cors?: CorsOptions; | ||
} | ||
|
||
export interface IConfigCache { | ||
ttl: TtlIdentifier; | ||
} | ||
|
||
export interface IConfigEngines { | ||
export interface ViewsEnginesOptions { | ||
engine: 'ejs' | 'hbs' | 'pug'; | ||
cacheTemplates?: boolean; | ||
} | ||
|
||
export interface IConfigCore { | ||
export interface GlobalSettings { | ||
env?: Environment; | ||
caching?: IConfigCache; | ||
proxy?: boolean; | ||
cookies?: CookieConfig; | ||
views?: { | ||
directory: string | string[]; | ||
engine?: IConfigEngines; | ||
}; | ||
trustProxy?: TrustProxyOption; | ||
proxyIpHeader?: string; | ||
proxyTrustCount?: number; | ||
} | ||
/** | ||
* Defines the overall structure for the configuration object. | ||
*/ | ||
export interface ConfigOptions { | ||
settings?: IConfigSettings; | ||
core?: IConfigCore; | ||
etag?: EtagIdentifier; | ||
poweredBy?: string | boolean; | ||
} |
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,19 @@ | ||
import { DynamicModule, Module } from '@gland/common'; | ||
import { COOKIES_METADATA } from '../constant'; | ||
import { CookieOptions } from '../interface/config.interface'; | ||
|
||
@Module({}) | ||
export class CookieModule { | ||
static forRoot(options: CookieOptions): DynamicModule { | ||
return { | ||
module: CookieModule, | ||
providers: [ | ||
{ | ||
provide: COOKIES_METADATA.COOKIES_WATERMARK, | ||
useValue: options, | ||
}, | ||
], | ||
exports: [CookieModule], | ||
}; | ||
} | ||
} |
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,25 @@ | ||
import { DynamicModule, Module } from '@gland/common'; | ||
import { CORS_METADATA } from '../constant'; | ||
import { CorsService } from '../services/cors.service'; | ||
import { CorsServiceConfig } from '../types/config.types'; | ||
/** | ||
* @module CorsModule | ||
* @description The CorsModule enables Cross-Origin Resource Sharing (CORS) functionality for the application. | ||
* It provides global configuration options and the service for handling CORS headers. | ||
*/ | ||
@Module({}) | ||
export class CorsModule { | ||
static forRoot<T>(options: CorsServiceConfig<T>): DynamicModule { | ||
return { | ||
module: CorsModule, | ||
|
||
providers: [ | ||
{ | ||
provide: CORS_METADATA.CORS_WATERMARK, | ||
useValue: options, | ||
}, | ||
], | ||
exports: [CorsService<T>], | ||
}; | ||
} | ||
} |
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,23 @@ | ||
import { DynamicModule, Module } from '@gland/common'; | ||
import { ConfigService } from '../services/global.service'; | ||
import { GlobalSettings } from '../interface/config.interface'; | ||
import { GLOBAL_METADATA } from '../constant'; | ||
/** | ||
* GlobalModule provides configuration management across the application. | ||
* @public | ||
*/ | ||
@Module({}) | ||
export class GlobalModule { | ||
static forRoot(config?: GlobalSettings): DynamicModule { | ||
return { | ||
module: GlobalModule, | ||
providers: [ | ||
{ | ||
provide: GLOBAL_METADATA.GLOBAL_WATERMARK, | ||
useValue: config, | ||
}, | ||
], | ||
exports: [ConfigService], | ||
}; | ||
} | ||
} |
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,5 @@ | ||
export * from './cookies.module'; | ||
export * from './cors.module'; | ||
export * from './global.module'; | ||
export * from './proxy.module'; | ||
export * from './views.module'; |
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,23 @@ | ||
import { DynamicModule, Module } from '@gland/common'; | ||
import { PROXY_METADATA } from '../constant'; | ||
import { ProxyServiceConfig } from '../interface/config.interface'; | ||
import { ProxyService } from '../services/proxy.service'; | ||
/** | ||
* @module ProxyModule | ||
* @description this module handles proxy settings and trusted proxies it lets you configure trust proxy options like the number of trusted hops and the header for client ip addresses you can use it to check if a request is from a trusted source based on rules or custom logic it supports dynamic configuration with the forRoot method so you can customize it easily | ||
*/ | ||
@Module({}) | ||
export class ProxyModule { | ||
static forRoot(options?: ProxyServiceConfig): DynamicModule { | ||
return { | ||
module: ProxyModule, | ||
providers: [ | ||
{ | ||
provide: PROXY_METADATA.PROXY_WATERMARK, | ||
useValue: options ?? {}, | ||
}, | ||
], | ||
exports: [ProxyService], | ||
}; | ||
} | ||
} |
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,32 @@ | ||
import { DynamicModule, Module } from '@gland/common'; | ||
import { VIEWS_METADATA } from '../constant'; | ||
import { ViewsConfig } from '../types/config.types'; | ||
import { ViewsService } from '../services/views.service'; | ||
/** | ||
* @module ViewsModule | ||
* @description | ||
* The ViewsModule is responsible for setting up the views system in the application. | ||
* It allows you to configure the view engine and the directory locations where | ||
* the views are stored. You can use the forRoot method to provide custom options | ||
* for the views configuration including the engine type like ejs pug or hbs | ||
* and the directories where the views are located. By default it uses ejs | ||
* as the template engine and a single directory '/views'. This module exports | ||
* the ViewsService which allows other parts of the application to access | ||
* and work with the view configurations and render templates based on the | ||
* provided options. | ||
*/ | ||
@Module({}) | ||
export class ViewsModule { | ||
static forRoot(options: ViewsConfig): DynamicModule { | ||
return { | ||
module: ViewsModule, | ||
providers: [ | ||
{ | ||
provide: VIEWS_METADATA.VIEWS_WATERMARK, | ||
useValue: options, | ||
}, | ||
], | ||
exports: [ViewsService], | ||
}; | ||
} | ||
} |
Oops, something went wrong.