Skip to content

Commit

Permalink
Add custom port CLI supoort
Browse files Browse the repository at this point in the history
  • Loading branch information
tvthatsme committed May 24, 2018
1 parent a86f630 commit fd05e9e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
4 changes: 3 additions & 1 deletion README.md
Expand Up @@ -40,6 +40,8 @@ Start the GraphQL server on localhost, port 3000.
json-graphql-server db.js
```

To use a port other than port 3000, you can run `json-graphql-server db.js -p <your port here>`

Now you can query your data in graphql. For instance, to issue the following query:

```graphql
Expand Down Expand Up @@ -533,7 +535,7 @@ Deploy with Heroku or Next.js.

## Roadmap

* CLI options (port, https, watch, delay, custom schema)
* CLI options (https, watch, delay, custom schema)
* Subscriptions
* Client-side mocking (à la [FakeRest](https://github.com/marmelab/FakeRest))

Expand Down
9 changes: 8 additions & 1 deletion bin/json-graphql-server.js
Expand Up @@ -10,12 +10,19 @@ var data = require(path.join(process.cwd(), dataFilePath));
var PORT = process.env.NODE_PORT || 3000;
var app = express();

process.argv.forEach((arg, index) => {
// allow a custom port via CLI
if (arg === '--p' && process.argv.length > index + 1) {
PORT = process.argv[index + 1];
}
});

app.use(cors());
app.use('/', JsonGraphqlServer(data));
app.listen(PORT);
var msg = `GraphQL server running with your data at http://localhost:${PORT}/`;
console.log(msg); // eslint-disable-line no-console

process.on('unhandledRejection', (reason, p) => {
console.log('Unhandled Rejection at: Promise', p, 'reason:', reason);
console.log('Unhandled Rejection at: Promise', p, 'reason:', reason);
});

0 comments on commit fd05e9e

Please sign in to comment.