Skip to content

Commit

Permalink
fix: disabled playground when environment is set to prod
Browse files Browse the repository at this point in the history
  • Loading branch information
osher-sade committed Mar 5, 2020
1 parent 3ce5a9e commit a6da83f
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ export { PolarisServer } from './server/polaris-server';
export { PolarisServerOptions } from './config/polaris-server-options';
export { MiddlewareConfiguration } from './config/middleware-configuration';
export { formatError } from './errors/error-formatter';
export * from 'apollo-server-errors';
export { PubSub, gql } from 'apollo-server-express';
export * from '@enigmatis/polaris-common';
export { Reality } from '@enigmatis/polaris-common';
Expand Down
22 changes: 17 additions & 5 deletions src/server/polaris-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { PolarisGraphQLLogger } from '@enigmatis/polaris-graphql-logger';
import { AbstractPolarisLogger, LoggerConfiguration } from '@enigmatis/polaris-logs';
import { PolarisLoggerPlugin } from '@enigmatis/polaris-middlewares';
import { makeExecutablePolarisSchema } from '@enigmatis/polaris-schema';
import { ApolloServer, ApolloServerExpressConfig } from 'apollo-server-express';
import { ApolloServer, ApolloServerExpressConfig, PlaygroundConfig } from 'apollo-server-express';
import { ApolloServerPlugin } from 'apollo-server-plugin-base';
import * as deepMerge from 'deepmerge';
import * as express from 'express';
Expand Down Expand Up @@ -112,10 +112,8 @@ export class PolarisServer {
schema: this.getSchemaWithMiddlewares(),
context: (ctx: ExpressContext) => this.getPolarisContext(ctx),
plugins,
playground: {
cdnUrl: '',
version: '',
},
playground: this.getPlaygroundConfig(),
introspection: this.getIntrospectionConfig(),
formatError,
subscriptions: {
path: `/${this.polarisServerConfig.applicationProperties.version}/subscription`,
Expand Down Expand Up @@ -170,6 +168,20 @@ export class PolarisServer {
return allowedMiddlewares;
}

private getPlaygroundConfig(): PlaygroundConfig {
return this.isProduction() ? false : { cdnUrl: '', version: '' };
}

private getIntrospectionConfig(): boolean | undefined {
return this.isProduction() ? false : undefined;
}

private isProduction(): boolean {
const environment: string | undefined = this.polarisServerConfig.applicationProperties
.environment;
return environment === 'prod' || environment === 'production';
}

private getPolarisContext = (context: ExpressContext): PolarisGraphQLContext => {
const { req, connection } = context;
const headers = req ? req.headers : connection?.context;
Expand Down
2 changes: 1 addition & 1 deletion test/errors/error-formatter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import * as status from 'http-status';
import { formatError } from '../../src';

describe('formatError tests', () => {
test('calling formatError with UserInputError, bad request status code is inside the extensions ', () => {
test('calling formatError with UserInputError, bad request status code is inside the extensions', () => {
const error = {
originalError: new UserInputError('test'),
extensions: {},
Expand Down

0 comments on commit a6da83f

Please sign in to comment.