@xeplr/base-apis 3.0.1 → 3.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -80,6 +80,7 @@ createApp(3000, 'myapp', {
80
80
  | option | |
81
81
  |---|---|
82
82
  | `requiredEnv` | variable names; any missing → message and `process.exit(1)` before anything starts |
83
+ | `host` | the address to listen on, e.g. `'127.0.0.1'` for a service that only nginx on the same machine may reach. Default: every address |
83
84
  | `auth` | the gate — see below. **On when omitted** |
84
85
  | `middleware` | array, mounted after the gate |
85
86
  | `rawBodyPaths` | path prefixes whose body is also kept byte for byte as `req.rawBody` (a `Buffer`) — see below |
package/express.js CHANGED
@@ -14,6 +14,8 @@ var logs = require('@xeplr/logs');
14
14
  * @param {string} appName - Service name (used for debug namespace and console logs)
15
15
  * @param {object} [options] - Configuration options
16
16
  * @param {string[]} [options.requiredEnv] - Mandatory env var names; missing ones abort startup
17
+ * @param {string} [options.host] - The address to listen on, e.g. '127.0.0.1' for a service only a
18
+ * proxy on the same machine may reach. Default: every address (Node's own default).
17
19
  * @param {object} [options.routes] - Route map: { '/path': router }
18
20
  * @param {object|false} [options.auth] - THE GATE, ON BY DEFAULT.
19
21
  * Omit it and every route requires a valid token, validated by asking the
@@ -251,7 +253,7 @@ function createApp(port, appName, options) {
251
253
 
252
254
  // ── Start HTTP server ──
253
255
  app.set('port', port);
254
- var server = createServer(app, port, appName);
256
+ var server = createServer(app, port, appName, options.host);
255
257
 
256
258
  return { app: app, server: server };
257
259
  }
package/lib/server.js CHANGED
@@ -7,12 +7,14 @@ function normalizePort(val) {
7
7
  return false;
8
8
  }
9
9
 
10
- function createServer(handler, port, name) {
10
+ function createServer(handler, port, name, host) {
11
11
  const dbg = require('debug')('architects:' + name);
12
12
  const normalizedPort = normalizePort(port);
13
13
 
14
14
  const server = http.createServer(handler);
15
- server.listen(normalizedPort);
15
+ // A host only for a port: a named pipe has none.
16
+ if (host && typeof normalizedPort === 'number') server.listen(normalizedPort, host);
17
+ else server.listen(normalizedPort);
16
18
 
17
19
  server.on('error', function onError(error) {
18
20
  if (error.syscall !== 'listen') throw error;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xeplr/base-apis",
3
- "version": "3.0.1",
3
+ "version": "3.0.2",
4
4
  "description": "Base API bootstrapper — Express and plain HTTP server factories with middleware injection",
5
5
  "main": "index.js",
6
6
  "bin": {