Skip to content

Commit

Permalink
feat: add config value for proxy chain length
Browse files Browse the repository at this point in the history
  • Loading branch information
skgndi12 committed Mar 18, 2024
1 parent ac5b4a1 commit 6da2468
Show file tree
Hide file tree
Showing 7 changed files with 9 additions and 2 deletions.
1 change: 1 addition & 0 deletions api/config/default.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ timeout:
http:
host: '127.0.0.1'
port: 8080
numTrustedProxies: 0
logger:
level: 'http' # Log only if less than or equal to this level
format: 'text'
Expand Down
1 change: 1 addition & 0 deletions api/config/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ timeout:
http:
host: '127.0.0.1'
port: 0 # PORT 0 randomly assigns a usable port. Set up for parallel testing.
numTrustedProxies: 0
logger:
level: 'silly' # Log only if less than or equal to this level
format: 'text'
Expand Down
1 change: 1 addition & 0 deletions api/src/config/loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export function buildHttpConfig(config: Config): HttpConfig {
env: config.env,
host: config.http.host,
port: config.http.port,
numTrustedProxies: config.http.numTrustedProxies,
cookieExpirationHours: config.jwt.expirationHour
};
}
Expand Down
2 changes: 2 additions & 0 deletions api/src/config/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@ export interface ConfigTimeout {
export interface ConfigHttp {
host: string;
port: number;
numTrustedProxies: number
}


export interface ConfigLogger {
level: LogLevel;
format: LogFormat;
Expand Down
2 changes: 1 addition & 1 deletion api/src/controller/http/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export class HttpServer {
public start = async (): Promise<void> => {
this.app = express();
this.app.disable('x-powered-by');
this.app.set('trust proxy', 0);
this.app.set('trust proxy', this.config.numTrustedProxies);
this.app.use(express.json());
await this.buildApiDocument();
this.app.use('/api', cookieParser());
Expand Down
1 change: 1 addition & 0 deletions api/src/controller/http/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ export interface HttpConfig {
env: string;
host: string;
port: number;
numTrustedProxies: number;
cookieExpirationHours: number;
}
3 changes: 2 additions & 1 deletion api/test/config/loader.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ describe('Test config loader', () => {
expect(loadConfig()).toStrictEqual({
env: 'test',
timeout: { shutdownSeconds: 30 },
http: { host: '127.0.0.1', port: 0 },
http: { host: '127.0.0.1', port: 0, numTrustedProxies: 0 },
logger: { level: 'silly', format: 'text' },
database: {
host: '127.0.0.1',
Expand Down Expand Up @@ -91,6 +91,7 @@ describe('Test build http config', () => {
env: 'test',
host: '127.0.0.1',
port: 0,
numTrustedProxies: 0,
cookieExpirationHours: 1
});
});
Expand Down

0 comments on commit 6da2468

Please sign in to comment.