Skip to content

Commit

Permalink
Docs
Browse files Browse the repository at this point in the history
  • Loading branch information
thiagobustamante committed May 19, 2017
1 parent af5cb38 commit 28c3459
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 17 deletions.
8 changes: 4 additions & 4 deletions src/config/admin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,23 @@ export interface AdminConfig {
protocol: ProtocolConfig;

/**
* Configurations for gateway users service
* Configurations for admin users service
*/
userService: UsersConfig;
/**
* Configurations for gateway access logger.
* Configurations for gateway admin server access logger.
*/
accessLogger?: AccessLoggerConfig;
/**
* If true, disabled the statistical data recording for admin tasks.
*/
disableStats?: boolean;
/**
* If provided, the service will publish all api documentation under thie informed path.
* If provided, the service will publish all api documentation under the informed path.
*/
apiDocs?: ApiDocs;
/**
* Configure cors support for API requests. It uses the [cors](https://www.npmjs.com/package/cors) module.
* Configure cors support for Admin API requests. It uses the [cors](https://www.npmjs.com/package/cors) module.
*/
cors?: CorsConfig;
}
Expand Down
7 changes: 7 additions & 0 deletions src/config/gateway.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { StatsConfig, statsConfigValidatorSchema } from './stats';
import { AdminConfig, adminConfigValidatorSchema } from './admin';
import { ProtocolConfig, protocolConfigSchema } from './protocol';
import { LoggerConfig, AccessLoggerConfig, loggerConfigSchema, accessLoggerConfigSchema } from './logger';
import { CorsConfig, corsConfigSchema } from './cors';
import { ValidationError } from '../error/errors';

/**
Expand Down Expand Up @@ -61,6 +62,11 @@ export interface GatewayConfig {
* If provided, Configure the admin service for the gateway
*/
admin?: AdminConfig;
/**
* Configure default cors support for API requests. It uses the [cors](https://www.npmjs.com/package/cors) module.
* It can be configured also in the API configuration
*/
cors?: CorsConfig;
}

export interface MonitorConfig {
Expand Down Expand Up @@ -167,6 +173,7 @@ const monitorConfigSchema = Joi.object().keys({
export const gatewayConfigValidatorSchema = Joi.object().keys({
accessLogger: accessLoggerConfigSchema,
admin: adminConfigValidatorSchema,
cors: corsConfigSchema,
logger: loggerConfigSchema,
monitor: Joi.array().items(monitorConfigSchema),
protocol: protocolConfigSchema.required(),
Expand Down
16 changes: 10 additions & 6 deletions src/config/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,6 @@ export interface AccessLoggerConfig {
* Enabling this will override any msg if true. Will only output colors when colorize set to true
*/
expressFormat?: boolean;
/**
* Color the text and status code, using the Express/morgan color palette
* (text: gray, status: default green, 3XX cyan, 4XX yellow, 5XX red).
*/
colorize?: boolean;
console?: LogConsoleConfig;
file?: LogFileConfig;
}
Expand All @@ -38,6 +33,10 @@ export interface LoggerConfig {
}

export interface LogConsoleConfig {
/**
* Level of messages that this logger should log.
*/
level?: string;
/**
* flag indicating if we should prepend output with timestamps (default true).
*/
Expand Down Expand Up @@ -87,6 +86,10 @@ export interface LogConsoleConfig {
}

export interface LogFileConfig {
/**
* Level of messages that this logger should log.
*/
level?: string;
/**
* The directory name where the logfiles will be saved.
*/
Expand Down Expand Up @@ -167,6 +170,7 @@ const logConsoleConfigSchema = Joi.object().keys({
depth: Joi.number().positive(),
humanReadableUnhandledException: Joi.boolean(),
json: Joi.boolean(),
level: Joi.string().valid('error', 'info', 'debug'),
prettyPrint: Joi.boolean(),
showLevel: Joi.boolean(),
silent: Joi.boolean(),
Expand All @@ -180,6 +184,7 @@ const logFileConfigSchema = Joi.object().keys({
depth: Joi.number().positive(),
eol: Joi.string(),
json: Joi.boolean(),
level: Joi.string().valid('error', 'info', 'debug'),
logstash: Joi.boolean(),
maxFiles: Joi.number().positive(),
maxRetries: Joi.number().positive(),
Expand All @@ -200,7 +205,6 @@ export let loggerConfigSchema = Joi.object().keys({
});

export let accessLoggerConfigSchema = Joi.object().keys({
colorize: Joi.boolean(),
console: logConsoleConfigSchema,
expressFormat: Joi.boolean(),
file: logFileConfigSchema,
Expand Down
4 changes: 0 additions & 4 deletions src/config/stats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,6 @@ export interface GranularityConfig {
* Time to live for each time serie
*/
ttl: string;
/**
* A prefix for the timeseries keys on database ()
*/
prefix?: string;
}

const granularityValidatorSchema = Joi.object().keys({
Expand Down
4 changes: 2 additions & 2 deletions src/cors/cors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import * as express from 'express';
import { ApiConfig } from '../config/api';
import { ApiCorsConfig } from '../config/cors';
import { ApiCorsConfig, CorsConfig } from '../config/cors';
import * as _ from 'lodash';
import * as pathUtil from 'path';
import * as Groups from '../group';
Expand Down Expand Up @@ -52,7 +52,7 @@ export class ApiCors {
this.setupMiddlewares(apiRouter, corsInfos);
}

configureCorsOptions(cors: ApiCorsConfig): corsMiddleware.CorsOptions {
configureCorsOptions(cors: CorsConfig): corsMiddleware.CorsOptions {
const corsOptions: corsMiddleware.CorsOptions = _.omit(cors, 'id', 'origin', 'maxAge', 'group');
if (cors.maxAge) {
corsOptions.maxAge = humanInterval(cors.maxAge);
Expand Down
11 changes: 10 additions & 1 deletion src/gateway.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import * as os from 'os';
import { AutoWired, Inject, Singleton } from 'typescript-ioc';
import { ConfigEvents } from './config/events';
import * as path from 'path';
import * as cors from 'cors';

class StatsController {
requestStats: Stats;
Expand Down Expand Up @@ -285,6 +286,8 @@ export class Gateway {
this.logger.debug('Configuring API Cors support');
}
this.apiCors.cors(apiRouter, api);
} else {
this.configureDefaultCors(apiRouter);
}
if (api.circuitBreaker) {
if (this.logger.isDebugEnabled()) {
Expand Down Expand Up @@ -418,7 +421,6 @@ export class Gateway {

private configureAdminCors() {
if (this.config.gateway.admin.cors) {
const cors = require('cors');
const corsOptions = new ApiCors().configureCorsOptions(this.config.gateway.admin.cors);
this.adminApp.use(cors(corsOptions));
}
Expand All @@ -445,6 +447,13 @@ export class Gateway {
}
}

private configureDefaultCors(apiRouter: express.Router) {
if (this.config.gateway.cors) {
const corsOptions = new ApiCors().configureCorsOptions(this.config.gateway.cors);
apiRouter.use(cors(corsOptions));
}
}

private configureStatsMiddleware(server: express.Router, key: string) {
const stats = this.createStatsController(key);
if (stats) {
Expand Down

0 comments on commit 28c3459

Please sign in to comment.