Skip to content

Commit 6d48a43

Browse files
authored
Merge pull request #114 from vantreeseba/add_hostname_cli_parameter
Add hostname cli parameter
2 parents c6dbcc8 + 33bff90 commit 6d48a43

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ json-graphql-server db.js
4242
```
4343

4444
To use a port other than 3000, you can run `json-graphql-server db.js --p <your port here>`
45+
To use a host other than localhost, you can run `json-graphql-server db.js --h <your host here>`
4546

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

bin/json-graphql-server.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,24 @@ var JsonGraphqlServer = require('../lib/json-graphql-server.node.min').default;
88
var dataFilePath = process.argv.length > 2 ? process.argv[2] : './data.json';
99
var data = require(path.join(process.cwd(), dataFilePath));
1010
var PORT = process.env.NODE_PORT || 3000;
11+
var HOST = process.env.NODE_HOST || 'localhost';
1112
var app = express();
1213

1314
process.argv.forEach((arg, index) => {
1415
// allow a custom port via CLI
1516
if (arg === '--p' && process.argv.length > index + 1) {
1617
PORT = process.argv[index + 1];
1718
}
19+
20+
if (arg === '--h' && process.argv.length > index + 1) {
21+
HOST = process.argv[index + 1];
22+
}
1823
});
1924

2025
app.use(cors());
2126
app.use('/', JsonGraphqlServer(data));
22-
app.listen(PORT);
23-
var msg = `GraphQL server running with your data at http://localhost:${PORT}/`;
27+
app.listen(PORT, HOST);
28+
var msg = `GraphQL server running with your data at http://${HOST}:${PORT}/`;
2429
console.log(msg); // eslint-disable-line no-console
2530

2631
process.on('unhandledRejection', (reason, p) => {

0 commit comments

Comments
 (0)