Skip to content

Commit 9319949

Browse files
committed
Make it easier to run a local playground for dev
1 parent fb2d29b commit 9319949

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,6 @@ To get started:
3838

3939
A few tips:
4040

41-
* Setting `playground: '/'` at the bottom of [`src/httptoolkit-server.ts`](src/httptoolkit-server.ts) will give you a GraphQL playground on http://localhost:45457/.
41+
* Running the server with `ENABLE_PLAYGROUND` set to `true` at the top of [`src/api-server.ts`](src/api-server.ts#L16) will give you a GraphQL playground on http://localhost:45457/.
4242
* New interceptors need to be added to `src/interceptors/index.ts`. They will also need to be added to [the UI](https://github.com/httptoolkit/httptoolkit-ui).
4343
* The tests assume that the required applications are installed to run every interceptor. See [.travis.yml](.travis.yml) for an example of how to set this up.

src/api-server.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ import { buildInterceptors, Interceptor } from './interceptors';
1313
import { ALLOWED_ORIGINS } from './constants';
1414
import { delay } from './util';
1515

16+
const ENABLE_PLAYGROUND = false;
17+
1618
const packageJson = require('../package.json');
1719

1820
const typeDefs = `
@@ -211,11 +213,13 @@ export class HttpToolkitServerApi extends events.EventEmitter {
211213
resolvers: buildResolvers(config, interceptors, this)
212214
});
213215

214-
this.graphql.use(corsGate({
215-
strict: true, // MUST send an allowed origin
216-
allowSafe: false, // Even for HEAD/GET requests (should be none anyway)
217-
origin: '' // No origin - we accept *no* same-origin requests
218-
}));
216+
if (!ENABLE_PLAYGROUND) {
217+
this.graphql.use(corsGate({
218+
strict: true, // MUST send an allowed origin
219+
allowSafe: false, // Even for HEAD/GET requests (should be none anyway)
220+
origin: '' // No origin - we accept *no* same-origin requests
221+
}));
222+
}
219223

220224
if (config.authToken) {
221225
// Optional auth token. This allows us to lock down UI/server communication further
@@ -240,7 +244,7 @@ export class HttpToolkitServerApi extends events.EventEmitter {
240244
// Hacky solution that lets us limit the server to only localhost,
241245
// and override the port from 4000 to something less likely to conflict.
242246
port: { port: 45457, host: '127.0.0.1' },
243-
playground: false,
247+
playground: ENABLE_PLAYGROUND ? "/" : false,
244248
cors: {
245249
origin: ALLOWED_ORIGINS,
246250
maxAge: 86400 // Cache this result for as long as possible

0 commit comments

Comments
 (0)