Skip to content

Commit

Permalink
Merge pull request #262 from vicchi/master
Browse files Browse the repository at this point in the history
Add host address env var override and update README
  • Loading branch information
orangejulius authored Jul 21, 2020
2 parents 7827d2d + 39e6274 commit 8ae075d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
8 changes: 5 additions & 3 deletions cmd/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@ const morgan = require( 'morgan' );
const logger = require('pelias-logger').get('interpolation');
const through = require( 'through2' );
const _ = require('lodash');
const util = require( 'util' );

// optionally override port using env var
// optionally override port/host using env var
const PORT = process.env.PORT || 3000;
const HOST = process.env.HOST || undefined;

// help text
if( process.argv.length !== 4 ){
Expand Down Expand Up @@ -218,10 +220,10 @@ app.use('/demo', express.static('demo'));
// app.use('/builds', express.static('/data/builds'));
// app.use('/builds', directory('/data/builds', { hidden: false, icons: false, view: 'details' }));

app.listen( PORT, function() {
app.listen( PORT, HOST, function() {

// force loading of libpostal
analyze.street( 'test street' );

console.log( 'server listening on port', PORT );
console.log(util.format( 'server listening on %s:%s', HOST || '0.0.0.0', PORT ));
});
10 changes: 9 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -219,13 +219,21 @@ note: the lat/lon values you provide are in order to disambiguate the street, th
### Start the web server
> run a web server which exposes the search APIs via an HTTP interface
note: you can set an environment variable named 'PORT' to change the port number.
```bash
./interpolate server address.db street.db

server listening on port 3000
```

#### Configuration via Environment Variables

The API supports additional environment variables that affect its operation:

| Environment Variable | Default | Description |
| -------------------- | ------- | ----------- |
| `HOST` | `undefined` | The network address that interpolation will bind to. Defaults to whatever the current Node.js default is, which is currently to listen on `0.0.0.0` (all interfaces). See the [Node.js Net documentation](https://nodejs.org/api/net.html#net_server_listen_port_host_backlog_callback) for more information. |
| `PORT` | `3000` | The TCP port that interpolation will use for incoming network connections |

### GET /search/{format}
> search the db for an address, return an interpolated value if an exact match does not exist
Expand Down

0 comments on commit 8ae075d

Please sign in to comment.