@cley_faye/boilerplate 3.7.2 → 3.8.0

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
@@ -426,7 +426,7 @@ import {appStart} from "@cley_faye/boilerplate/lib/express.js";
426
426
 
427
427
  appStart({
428
428
  app,
429
- allowNonLocal: false,
429
+ listenInterface: false,
430
430
  port: 3000,
431
431
  shutdownFunction: () => {;},
432
432
  logger: consoleLogger,
@@ -435,7 +435,8 @@ appStart({
435
435
 
436
436
  The settings are:
437
437
 
438
- - allowNonLocal: listen only to localhost or not
438
+ - listenInterface: listen only to localhost or not. Can also be used to specify the address of an
439
+ interface to bind to.
439
440
  - port: port to listen to. Can be 0 to use a random available port
440
441
  - shutdownFunction: a function to call after the server stop listening
441
442
  - logger: a winston logger to log that the server started listening
package/lib/express.d.ts CHANGED
@@ -106,7 +106,16 @@ export declare const createPipeline: (settings: PipelineSettings, debugLog?: Log
106
106
  export declare const setViewEngine: (app: express.Express, viewEngine: string, viewsDirectory: string, extraLocals?: Record<string, string | number> | undefined) => void;
107
107
  export interface StartDefinition {
108
108
  app: express.Application;
109
+ /** @deprecated use listenInterface instead */
109
110
  allowNonLocal?: boolean;
111
+ /**
112
+ * Which interface to listen on.
113
+ *
114
+ * Defaults to `false` which means listen only on localhost.
115
+ * Set to `true` to listen on all interfaces
116
+ * Set to an IP to bind on a specific interface.
117
+ */
118
+ listenInterface?: boolean | string;
110
119
  port?: number;
111
120
  shutdownFunction?: () => void;
112
121
  logger?: winston.Logger;
@@ -135,4 +144,4 @@ export interface StartResult {
135
144
  *
136
145
  * @property server
137
146
  */
138
- export declare const appStart: ({ app, allowNonLocal, port, shutdownFunction, logger, }: StartDefinition) => Promise<StartResult>;
147
+ export declare const appStart: ({ app, allowNonLocal, listenInterface, port, shutdownFunction, logger, }: StartDefinition) => Promise<StartResult>;
package/lib/express.js CHANGED
@@ -169,7 +169,7 @@ exports.setViewEngine = setViewEngine;
169
169
  *
170
170
  * @property server
171
171
  */
172
- const appStart = ({ app, allowNonLocal, port, shutdownFunction, logger, }) => new Promise(resolve => {
172
+ const appStart = ({ app, allowNonLocal, listenInterface, port, shutdownFunction, logger, }) => new Promise(resolve => {
173
173
  let server = null;
174
174
  const readyCallback = () => {
175
175
  if (server === null) {
@@ -186,9 +186,18 @@ const appStart = ({ app, allowNonLocal, port, shutdownFunction, logger, }) => ne
186
186
  server,
187
187
  });
188
188
  };
189
- server = allowNonLocal
190
- ? app.listen(port ?? 0, readyCallback)
191
- : app.listen(port ?? 0, "localhost", readyCallback);
189
+ if (allowNonLocal !== undefined && listenInterface !== undefined) {
190
+ throw new Error("You can't specify both allowNonLocal and listenInterface at the same time");
191
+ }
192
+ if (allowNonLocal || listenInterface === true) {
193
+ server = app.listen(port ?? 0, readyCallback);
194
+ }
195
+ else if (typeof listenInterface === "string") {
196
+ server = app.listen(port ?? 0, listenInterface, readyCallback);
197
+ }
198
+ else {
199
+ server = app.listen(port ?? 0, "localhost", readyCallback);
200
+ }
192
201
  if (shutdownFunction) {
193
202
  server.on("close", shutdownFunction);
194
203
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cley_faye/boilerplate",
3
- "version": "3.7.2",
3
+ "version": "3.8.0",
4
4
  "description": "Boilerplate code generator for generic projects",
5
5
  "repository": {
6
6
  "type": "git",