Skip to content

Commit

Permalink
fix: correctly support live data
Browse files Browse the repository at this point in the history
fix ##18
  • Loading branch information
jlengstorf committed Oct 16, 2017
1 parent 57a205a commit e0539d2
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
5 changes: 4 additions & 1 deletion src/dev/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,15 @@ import { grampsExpress } from '../index';

const app = express();

const enableMockData =
process.env.NODE_ENV !== 'production' && process.env.GRAMPS_MODE !== 'live';

app.use(bodyParser.json());

app.use(
grampsExpress({
dataSources: [],
enableMockData: process.env.NODE_ENV !== 'production',
enableMockData,
extraContext: req => ({ req }),
}),
);
Expand Down
6 changes: 5 additions & 1 deletion src/dev/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,17 @@ import app from './app';

// Get the port from the various places it can be set
const port = parseInt(process.env.PORT, 10) || 8080;
const mode =
process.env.NODE_ENV === 'production' || process.env.GRAMPS_MODE === 'live'
? 'live'
: 'mock';

// Start the server, then display app details and URL info.
app.set('port', port);
app.listen(app.get('port'), () => {
const message = [
`${EOL}============================================================`,
` GrAMPS is running in ${process.env.NODE_ENV} mode on port ${port}`,
` GrAMPS is running in ${mode} mode on port ${port}`,
'',
` GraphiQL: http://localhost:${port}/graphiql`,
`============================================================${EOL}`,
Expand Down
17 changes: 17 additions & 0 deletions test/dev/server-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,21 @@ describe('dev/server', () => {
it('calls the listen method with the correct arguments', () => {
expect(app.listen.mock.calls[0][0]).toBe(9999);
});

it('correctly sets the mode based on the env', () => {
jest.resetModules();

process.env.NODE_ENV = 'production';

// eslint-disable-next-line global-require
const logger = require('../../src/lib/defaultLogger');
const spy = jest.spyOn(logger, 'info');

// eslint-disable-next-line global-require
require('../../src/dev/server');

expect(spy).toHaveBeenCalledWith(
expect.stringMatching(/running in live mode/),
);
});
});

0 comments on commit e0539d2

Please sign in to comment.