@haibun/web-server-express 0.2.1 → 1.1.1

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.
@@ -0,0 +1,15 @@
1
+ export declare const WEBSERVER = "webserver";
2
+ export declare const CHECK_LISTENER = "CHECK_LISTENER";
3
+ import * as express from 'express';
4
+ export interface IWebServer {
5
+ addStaticFolder(subdir: string): Promise<string | undefined>;
6
+ addKnownStaticFolder(subdir: string, mountAt?: string): Promise<string | undefined>;
7
+ listen(): Promise<IWebServer>;
8
+ close(): Promise<void>;
9
+ addRoute(type: TRouteType, path: string, route: TRequestHandler): void;
10
+ }
11
+ export declare type TRouteType = 'get';
12
+ export declare type IRequest = typeof express.request;
13
+ export declare type IResponse = typeof express.response;
14
+ export declare type TRequestHandler = (req: IRequest, res: IResponse) => void;
15
+ //# sourceMappingURL=defs.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"defs.d.ts","sourceRoot":"","sources":["../src/defs.ts"],"names":[],"mappings":"AACA,eAAO,MAAM,SAAS,cAAc,CAAC;AACrC,eAAO,MAAM,cAAc,mBAAmB,CAAC;AAC/C,OAAO,KAAK,OAAO,MAAM,SAAS,CAAC;AAEnC,MAAM,WAAW,UAAU;IACzB,eAAe,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAAC;IAC7D,oBAAoB,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAAC;IACpF,MAAM,IAAI,OAAO,CAAC,UAAU,CAAC,CAAC;IAC9B,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IACvB,QAAQ,CAAC,IAAI,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,eAAe,GAAG,IAAI,CAAC;CACxE;AAED,oBAAY,UAAU,GAAG,KAAK,CAAC;AAE/B,oBAAY,QAAQ,GAAG,OAAO,OAAO,CAAC,OAAO,CAAC;AAE9C,oBAAY,SAAS,GAAG,OAAO,OAAO,CAAC,QAAQ,CAAC;AAEhD,oBAAY,eAAe,GAAG,CAAC,GAAG,EAAE,QAAQ,EAAE,GAAG,EAAE,SAAS,KAAK,IAAI,CAAC"}
package/build/defs.js ADDED
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CHECK_LISTENER = exports.WEBSERVER = void 0;
4
+ exports.WEBSERVER = 'webserver';
5
+ exports.CHECK_LISTENER = 'CHECK_LISTENER';
6
+ //# sourceMappingURL=defs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"defs.js","sourceRoot":"","sources":["../src/defs.ts"],"names":[],"mappings":";;;AACa,QAAA,SAAS,GAAG,WAAW,CAAC;AACxB,QAAA,cAAc,GAAG,gBAAgB,CAAC"}
@@ -1,19 +1,24 @@
1
1
  import { RequestHandler } from 'express';
2
- import { TLogger } from '@haibun/core/build/lib/defs';
3
- import { IWebServer, TRouteType } from './web-server-stepper';
2
+ import { IWebServer, TRouteType } from './defs';
3
+ import { ILogger } from '@haibun/core/src/lib/interfaces/logger';
4
4
  export declare const DEFAULT_PORT = 8123;
5
5
  export declare class ServerExpress implements IWebServer {
6
- logger: TLogger;
7
- static listener: any;
8
- static app: import("express-serve-static-core").Express;
6
+ logger: ILogger;
7
+ static listening: boolean;
8
+ listener: any;
9
+ app: import("express-serve-static-core").Express;
9
10
  static mounted: {
10
11
  [named: string]: string;
11
12
  };
12
13
  base: string;
13
- constructor(logger: TLogger, base: string, port?: number);
14
- listening(port: number): Promise<void>;
15
- addRoute(type: TRouteType, path: string, route: RequestHandler): Promise<any>;
16
- addStaticFolder(subdir: string): Promise<string | undefined>;
14
+ port: number;
15
+ constructor(logger: ILogger, base: string, port?: number);
16
+ listen(): Promise<IWebServer>;
17
+ addRoute(type: TRouteType, path: string, route: RequestHandler): Promise<void>;
18
+ addMounted(path: string, what: string): Promise<void>;
19
+ addStaticFolder(relativeFolder: string, mountAt?: string): Promise<string | undefined>;
20
+ addKnownStaticFolder(folder: string, mountAt?: string): Promise<string | undefined>;
21
+ doAddStaticFolder(folder: string, mountAt?: string): Promise<string | undefined>;
17
22
  checkMountBadOrMounted(loc: string, what: string): boolean;
18
23
  close(): Promise<void>;
19
24
  }
@@ -1 +1 @@
1
- {"version":3,"file":"server-express.d.ts","sourceRoot":"","sources":["../src/server-express.ts"],"names":[],"mappings":"AACA,OAAgB,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAElD,OAAO,EAAE,OAAO,EAAE,MAAM,6BAA6B,CAAC;AACtD,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAE9D,eAAO,MAAM,YAAY,OAAO,CAAC;AAEjC,qBAAa,aAAc,YAAW,UAAU;IAC9C,MAAM,EAAE,OAAO,CAAC;IAChB,MAAM,CAAC,QAAQ,EAAE,GAAG,CAAC;IACrB,MAAM,CAAC,GAAG,8CAAa;IACvB,MAAM,CAAC,OAAO,EAAE;QAAE,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAAA;KAAE,CAAM;IACjD,IAAI,EAAE,MAAM,CAAC;gBACD,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,GAAE,MAAqB;IAKhE,SAAS,CAAC,IAAI,EAAE,MAAM;IAQtB,QAAQ,CAAC,IAAI,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,cAAc;IAc9D,eAAe,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC;IAyBlE,sBAAsB,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO;IAqBpD,KAAK;CAIZ"}
1
+ {"version":3,"file":"server-express.d.ts","sourceRoot":"","sources":["../src/server-express.ts"],"names":[],"mappings":"AACA,OA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exports.ServerExpress = exports.DEFAULT_PORT = void 0;
7
7
  const fs_1 = require("fs");
8
8
  const express_1 = __importDefault(require("express"));
9
+ const cookie_parser_1 = __importDefault(require("cookie-parser"));
9
10
  exports.DEFAULT_PORT = 8123;
10
11
  class ServerExpress {
11
12
  constructor(logger, base, port = exports.DEFAULT_PORT) {
13
+ this.app = express_1.default();
12
14
  this.logger = logger;
13
15
  this.base = base;
16
+ this.port = port;
17
+ this.app.use(cookie_parser_1.default());
14
18
  }
15
- async listening(port) {
16
- if (!ServerExpress.listener) {
17
- ServerExpress.listener = await ServerExpress.app.listen(port, () => this.logger.log(`Server listening on port: ${port}`));
19
+ async listen() {
20
+ if (!ServerExpress.listening) {
21
+ try {
22
+ ServerExpress.listening = true;
23
+ this.listener = await this.app.listen(this.port, () => this.logger.log(`Server listening on port: ${this.port}`));
24
+ this.logger.log('express listening');
25
+ }
26
+ catch (e) {
27
+ console.error(e);
28
+ }
18
29
  }
19
30
  else {
20
- this.logger.log('express already started');
31
+ this.logger.log('express already listening');
21
32
  }
33
+ return this;
22
34
  }
23
35
  async addRoute(type, path, route) {
24
36
  try {
25
37
  const alreadyMounted = this.checkMountBadOrMounted(path, route.toString());
26
38
  if (alreadyMounted) {
39
+ this.logger.debug(`already mount ${path}`);
27
40
  return;
28
41
  }
29
42
  }
30
43
  catch (e) {
31
- return e.message;
44
+ throw (e);
32
45
  }
33
46
  this.logger.log(`serving route from ${path}`);
34
- await ServerExpress.app[type](path, route);
47
+ await this.app[type](path, route);
48
+ await this.addMounted(path, route.toString());
35
49
  }
36
- async addStaticFolder(subdir) {
37
- const folder = [this.base, subdir].join('/');
38
- const loc = '/';
50
+ async addMounted(path, what) {
51
+ ServerExpress.mounted[path] = what;
52
+ if (!this.listener) {
53
+ await this.listen();
54
+ }
55
+ }
56
+ // add a static folder restricted to relative paths from files
57
+ async addStaticFolder(relativeFolder, mountAt = '/') {
58
+ if (relativeFolder !== relativeFolder.replace(/[^a-zA-Z-0-9\/-_]/g, '').replace(/^\//g, '')) {
59
+ throw Error(`mount folder ${relativeFolder} has illegal characters`);
60
+ }
61
+ const folder = [this.base, relativeFolder].join('/');
62
+ return this.doAddStaticFolder(folder, mountAt);
63
+ }
64
+ // add a static folder at any path
65
+ async addKnownStaticFolder(folder, mountAt = '/') {
66
+ return this.doAddStaticFolder(folder, mountAt);
67
+ }
68
+ async doAddStaticFolder(folder, mountAt = '/') {
39
69
  try {
40
- const alreadyMounted = this.checkMountBadOrMounted(loc, folder);
70
+ const alreadyMounted = this.checkMountBadOrMounted(mountAt, folder);
41
71
  if (alreadyMounted) {
72
+ // FIXME
42
73
  return;
43
74
  }
44
75
  }
@@ -52,21 +83,12 @@ class ServerExpress {
52
83
  if (!stat.isDirectory()) {
53
84
  throw Error(`"${folder}" is not a directory`);
54
85
  }
55
- ServerExpress.mounted[loc] = folder;
56
- this.logger.info(`serving files from ${folder} at ${loc}`);
57
- await ServerExpress.app.use(express_1.default.static(folder));
86
+ this.logger.info(`serving files from ${folder} at ${mountAt}`);
87
+ await this.app.use(mountAt, express_1.default.static(folder));
88
+ await this.addMounted(mountAt, folder);
58
89
  return;
59
90
  }
60
91
  checkMountBadOrMounted(loc, what) {
61
- if (!ServerExpress.listener) {
62
- throw Error(`listening must be called before mount`);
63
- }
64
- if (!loc) {
65
- throw Error(`missing mount location`);
66
- }
67
- if (loc !== loc.replace(/[^a-zA-Z-0-9\/]/g, '')) {
68
- throw Error(`mount folder ${loc} has illegal characters`);
69
- }
70
92
  const alreadyMounted = ServerExpress.mounted[loc];
71
93
  if (alreadyMounted === what) {
72
94
  this.logger.log(`${alreadyMounted} already mounted at ${loc}`);
@@ -79,10 +101,10 @@ class ServerExpress {
79
101
  }
80
102
  async close() {
81
103
  this.logger.info('closing server');
82
- await ServerExpress.listener?.close();
104
+ await this.listener?.close();
83
105
  }
84
106
  }
85
107
  exports.ServerExpress = ServerExpress;
86
- ServerExpress.app = express_1.default();
108
+ ServerExpress.listening = false;
87
109
  ServerExpress.mounted = {};
88
110
  //# sourceMappingURL=server-express.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"server-express.js","sourceRoot":"","sources":["../src/server-express.ts"],"names":[],"mappings":";;;;;;AAAA,2BAA0C;AAC1C,sDAAkD;AAKrC,QAAA,YAAY,GAAG,IAAI,CAAC;AAEjC,MAAa,aAAa;IAMxB,YAAY,MAAe,EAAE,IAAY,EAAE,OAAe,oBAAY;QACpE,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACnB,CAAC;IAED,KAAK,CAAC,SAAS,CAAC,IAAY;QAC1B,IAAI,CAAC,aAAa,CAAC,QAAQ,EAAE;YAC3B,aAAa,CAAC,QAAQ,GAAG,MAAM,aAAa,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,6BAA6B,IAAI,EAAE,CAAC,CAAC,CAAC;SAC3H;aAAM;YACL,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,yBAAyB,CAAC,CAAC;SAC5C;IACH,CAAC;IAED,KAAK,CAAC,QAAQ,CAAC,IAAgB,EAAE,IAAY,EAAE,KAAqB;QAClE,IAAI;YACF,MAAM,cAAc,GAAG,IAAI,CAAC,sBAAsB,CAAC,IAAI,EAAE,KAAK,CAAC,QAAQ,EAAE,CAAC,CAAC;YAC3E,IAAI,cAAc,EAAE;gBAClB,OAAO;aACR;SACF;QAAC,OAAO,CAAM,EAAE;YACf,OAAO,CAAC,CAAC,OAAO,CAAC;SAClB;QACD,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,sBAAsB,IAAI,EAAE,CAAC,CAAC;QAE9C,MAAM,aAAa,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;IAC7C,CAAC;IAED,KAAK,CAAC,eAAe,CAAC,MAAc;QAClC,MAAM,MAAM,GAAG,CAAC,IAA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,MAAM,OAAO,OAAO,EAAE,CAAC,CAAC;QAC/D,MAAM,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,OAAO,EAAE,iBAAO,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC;QACpD,MAAM,IAAI,CAAC,UAAU,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;QACvC,OAAO;IACT,CAAC;IAED,sBAAsB,CAAC,GAAW,EAAE,IAAY;QAC9C,MAAM,cAAc,GAAG,aAAa,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;QAClD,IAAI,cAAc,KAAK,IAAI,EAAE;YAC3B,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG,cAAc,uBAAuB,GAAG,EAAE,CAAC,CAAC;YAC/D,OAAO,IAAI,CAAC;SACb;aAAM,IAAI,cAAc,IAAI,cAAc,KAAK,IAAI,EAAE;YACpD,MAAM,KAAK,CAAC,gBAAgB,IAAI,OAAO,GAAG,KAAK,cAAc,sBAAsB,CAAC,CAAC;SACtF;QACD,OAAO,KAAK,CAAC;IACf,CAAC;IAED,KAAK,CAAC,KAAK;QACT,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,gBAAgB,CAAC,CAAC;QACnC,MAAM,IAAI,CAAC,QAAQ,EAAE,KAAK,EAAE,CAAC;IAC/B,CAAC;;AA7GH,sCA8GC;AA5GQ,uBAAS,GAAY,KAAK,CAAC;AAG3B,qBAAO,GAAgC,EAAE,CAAC"}
@@ -1,62 +1,42 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
- }) : (function(o, m, k, k2) {
6
- if (k2 === undefined) k2 = k;
7
- o[k2] = m[k];
8
- }));
9
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
- Object.defineProperty(o, "default", { enumerable: true, value: v });
11
- }) : function(o, v) {
12
- o["default"] = v;
13
- });
14
- var __importStar = (this && this.__importStar) || function (mod) {
15
- if (mod && mod.__esModule) return mod;
16
- var result = {};
17
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18
- __setModuleDefault(result, mod);
19
- return result;
20
- };
21
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
22
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
23
4
  };
24
5
  Object.defineProperty(exports, "__esModule", { value: true });
25
- const node_fetch_1 = __importDefault(require("node-fetch"));
6
+ const web_http_1 = __importDefault(require("@haibun/web-http/build/web-http"));
26
7
  const util_1 = require("@haibun/core/build/lib/util");
27
- const TestSteps_1 = require("@haibun/core/build/lib/TestSteps");
28
- const web_server_stepper_1 = __importStar(require("./web-server-stepper"));
8
+ const defs_1 = require("./defs");
9
+ const web_server_stepper_1 = __importDefault(require("./web-server-stepper"));
10
+ const defs_2 = require("@haibun/core/build/lib/defs");
11
+ const lib_1 = require("@haibun/core/src/lib/test/lib");
12
+ const web_server_stepper_2 = __importDefault(require("./web-server-stepper"));
29
13
  describe('route mount', () => {
30
14
  it('mounts a route', async () => {
31
- const TestRoute = class TestRoute {
32
- constructor(world) {
15
+ const TestRoute = class TestRoute extends defs_2.AStepper {
16
+ constructor() {
17
+ super(...arguments);
33
18
  this.steps = {
34
19
  addRoute: {
35
20
  gwta: 'serve test route to {loc}',
36
21
  action: async ({ loc }) => {
37
22
  const route = (req, res) => res.status(200).send('ok');
38
- const webserver = util_1.getFromRuntime(this.world.runtime, web_server_stepper_1.WEBSERVER);
39
- const checkListener = util_1.getFromRuntime(this.world.runtime, web_server_stepper_1.CHECK_LISTENER);
40
- await checkListener(this.world.options, webserver);
23
+ const webserver = await util_1.getFromRuntime(this.getWorld().runtime, defs_1.WEBSERVER);
41
24
  await webserver.addRoute('get', loc, route);
42
25
  return util_1.actionOK();
43
26
  },
44
27
  },
45
28
  };
46
- this.world = world;
47
29
  }
48
30
  };
49
- const { world } = util_1.getDefaultWorld();
50
- const { result, steppers } = await TestSteps_1.testRun('/test/route', [web_server_stepper_1.default, TestRoute], world, {
31
+ const wss = new web_server_stepper_2.default();
32
+ const feature = { path: '/features/test.feature', content: `serve test route to /test\nwebserver is listening\nfetch from http://localhost:8124/test is "ok"` };
33
+ const { result } = await lib_1.testWithDefaults([feature], [web_server_stepper_1.default, TestRoute, web_http_1.default], {
51
34
  options: {},
52
35
  extraOptions: {
53
- [`HAIBUN_O_${web_server_stepper_1.WEBSERVER_STEPPER.toUpperCase()}_PORT`]: '8124',
36
+ [util_1.getStepperOptionName(wss, 'PORT')]: '8124',
54
37
  },
55
38
  });
56
39
  expect(result.ok).toBe(true);
57
- const content = await node_fetch_1.default('http://localhost:8124/test');
58
- expect(await content.text()).toEqual('ok');
59
- util_1.getStepper(steppers, web_server_stepper_1.WEBSERVER_STEPPER).close();
60
40
  });
61
41
  });
62
42
  //# sourceMappingURL=web-server-stepper-route.test.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"web-server-stepper-route.test.js","sourceRoot":"","sources":["../src/web-server-stepper-route.test.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAAA,4DAA+B;AAG/B,sDAAoG;AACpG,gEAA2D;AAE3D,2EAA2I;AAG3I,QAAQ,CAAC,aAAa,EAAE,GAAG,EAAE;IAC3B,EAAE,CAAC,gBAAgB,EAAE,KAAK,IAAI,EAAE;QAC9B,MAAM,SAAS,GAA0B,MAAM,SAAS;YAEtD,YAAY,KAAa;gBAGzB,UAAK,GAAG;oBACN,QAAQ,EAAE;wBACR,IAAI,EAAE,2BAA2B;wBACjC,MAAM,EAAE,KAAK,EAAE,EAAE,GAAG,EAAc,EAAE,EAAE;4BACpC,MAAM,KAAK,GAAG,CAAC,GAAY,EAAE,GAAa,EAAE,EAAE,CAAC,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;4BA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,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC/B,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
@@ -1,20 +1,48 @@
1
- import { IExtensionConstructor, TOptions } from '@haibun/core/build/lib/defs';
2
- import { RequestHandler } from 'express';
3
- export declare const WEBSERVER = "webserver";
4
- export declare const WEBSERVER_STEPPER = "WebServerStepper";
5
- export declare const CHECK_LISTENER = "CHECK_LISTENER";
6
- declare const WebServerStepper: IExtensionConstructor;
1
+ import { TWorld, TNamed, TOptions } from '@haibun/core/build/lib/defs';
2
+ import { IWebServer } from './defs';
3
+ import { ServerExpress } from './server-express';
4
+ declare const WebServerStepper: {
5
+ new (): {
6
+ webserver: ServerExpress | undefined;
7
+ options: {
8
+ PORT: {
9
+ desc: string;
10
+ parse: (port: string) => {
11
+ error: string;
12
+ result?: undefined;
13
+ } | {
14
+ result: number;
15
+ error?: undefined;
16
+ };
17
+ };
18
+ };
19
+ setWorld(world: TWorld): void;
20
+ close(): Promise<void>;
21
+ steps: {
22
+ isListening: {
23
+ gwta: string;
24
+ action: () => Promise<import("@haibun/core/build/lib/defs").TOKActionResult>;
25
+ };
26
+ showMounts: {
27
+ gwta: string;
28
+ action: () => Promise<import("@haibun/core/build/lib/defs").TOKActionResult>;
29
+ };
30
+ serveFiles: {
31
+ gwta: string;
32
+ action: ({ loc }: TNamed) => Promise<import("@haibun/core/build/lib/defs").TOKActionResult | import("@haibun/core/build/lib/defs").TNotOKActionResult>;
33
+ build: ({ loc }: TNamed) => Promise<import("@haibun/core/build/lib/defs").TOKActionResult>;
34
+ };
35
+ };
36
+ world?: TWorld | undefined;
37
+ endFeature?(): void;
38
+ onFailure?(result: import("@haibun/core/build/lib/defs").TStepResult): void;
39
+ getWorld(): TWorld;
40
+ };
41
+ };
7
42
  export default WebServerStepper;
8
43
  export declare type ICheckListener = (options: TOptions, webserver: IWebServer) => void;
9
44
  export interface IWebServerStepper {
10
45
  webserver: IWebServer;
11
46
  close: () => void;
12
- checkListener: ICheckListener;
13
47
  }
14
- export interface IWebServer {
15
- addStaticFolder(subdir: string): Promise<string | undefined>;
16
- listening(port: number): void;
17
- addRoute(type: TRouteType, path: string, route: RequestHandler): void;
18
- }
19
- export declare type TRouteType = 'get';
20
48
  //# sourceMappingURL=web-server-stepper.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"web-server-stepper.d.ts","sourceRoot":"","sources":["../src/web-server-stepper.ts"],"names":[],"mappings":"AAAA,OAAO,EAAyB,qBAAqB,EAA0B,QAAQ,EAAE,MAAM,6BAA6B,CAAC;AAE7H,OAAO,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAGzC,eAAO,MAAM,SAAS,cAAc,CAAC;AACrC,eAAO,MAAM,iBAAiB,qBAAqB,CAAC;AACpD,eAAO,MAAM,cAAc,mBAAmB,CAAC;AAE/C,QAAA,MAAM,gBAAgB,EAAE,qBAsCvB,CAAC;AACF,eAAe,gBAAgB,CAAC;AAEhC,oBAAY,cAAc,GAAG,CAAC,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,UAAU,KAAK,IAAI,CAAC;AAChF,MAAM,WAAW,iBAAiB;IAChC,SAAS,EAAE,UAAU,CAAC;IACtB,KAAK,EAAE,MAAM,IAAI,CAAC;IAClB,aAAa,EAAE,cAAc,CAAC;CAC/B;AAED,MAAM,WAAW,UAAU;IACzB,eAAe,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAAC;IAC7D,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IAC9B,QAAQ,CAAC,IAAI,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,cAAc,GAAG,IAAI,CAAC;CACvE;AAED,oBAAY,UAAU,GAAG,KAAK,CAAC"}
1
+ {"version":3,"file":"web-server-stepper.d.ts","sourceRoot":"","sources":["../src/web-server-stepper.ts"],"names":[],"mappings":"AAAA,OAAO,EAAmB,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAY,MAAM,6BAA6B,CAAC;AAElG,OAAO,EAAE,UAAU,EAAc,MAAM,QAAQ,CAAC;AAChD,OAAO,EAAE,aAAa,EAAgB,MAAM,kBAAkB,CAAC;AAE/D,QAAA,MAAM,gBAAgB;;mBACT,aAAa,GAAG,SAAS;;;;8BAKlB,MAAM;;;;;;;;;wBAIR,MAAM;;;;;;;;;;;;;kCA8BM,MAAM;iCAOP,MAAM;;;;;;;;CAMlC,CAAC;AACF,eAAe,gBAAgB,CAAC;AAEhC,oBAAY,cAAc,GAAG,CAAC,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,UAAU,KAAK,IAAI,CAAC;AAChF,MAAM,WAAW,iBAAiB;IAChC,SAAS,EAAE,UAAU,CAAC;IACtB,KAAK,EAAE,MAAM,IAAI,CAAC;CACnB"}
@@ -1,43 +1,59 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.CHECK_LISTENER = exports.WEBSERVER_STEPPER = exports.WEBSERVER = void 0;
4
3
  const defs_1 = require("@haibun/core/build/lib/defs");
5
4
  const util_1 = require("@haibun/core/build/lib/util");
5
+ const defs_2 = require("./defs");
6
6
  const server_express_1 = require("./server-express");
7
- exports.WEBSERVER = 'webserver';
8
- exports.WEBSERVER_STEPPER = 'WebServerStepper';
9
- exports.CHECK_LISTENER = 'CHECK_LISTENER';
10
- const WebServerStepper = class WebServerStepper {
11
- constructor(world) {
7
+ const WebServerStepper = class WebServerStepper extends defs_1.AStepper {
8
+ constructor() {
9
+ super(...arguments);
12
10
  this.options = {
13
11
  PORT: {
14
12
  desc: `change web server port from ${server_express_1.DEFAULT_PORT}`,
15
- parse: (port) => parseInt(port, 10),
13
+ parse: (port) => util_1.intOrError(port)
16
14
  },
17
15
  };
18
16
  this.steps = {
17
+ isListening: {
18
+ gwta: 'webserver is listening',
19
+ action: async () => {
20
+ await this.webserver.listen();
21
+ return defs_1.OK;
22
+ },
23
+ },
24
+ showMounts: {
25
+ gwta: 'show mounts',
26
+ action: async () => {
27
+ const mounts = server_express_1.ServerExpress.mounted;
28
+ this.getWorld().logger.info(`mounts: ${JSON.stringify(mounts)}`);
29
+ return defs_1.OK;
30
+ },
31
+ },
19
32
  serveFiles: {
20
33
  gwta: 'serve files from {loc}',
21
34
  action: async ({ loc }) => {
22
- await WebServerStepper.checkListener(this.world.options, this.world.runtime[exports.WEBSERVER]);
23
- const ws = await this.world.runtime[exports.WEBSERVER];
35
+ const ws = await util_1.getFromRuntime(this.getWorld().runtime, defs_2.WEBSERVER);
24
36
  const error = await ws.addStaticFolder(loc);
37
+ this.getWorld().shared.set('file_location', loc);
25
38
  return error === undefined ? defs_1.OK : util_1.actionNotOK(error);
26
39
  },
40
+ build: async ({ loc }) => {
41
+ this.getWorld().shared.set('file_location', loc);
42
+ return defs_1.OK;
43
+ }
27
44
  },
28
45
  };
46
+ }
47
+ setWorld(world) {
29
48
  this.world = world;
30
- this.webserver = new server_express_1.ServerExpress(this.world.logger, [process.cwd(), 'files'].join('/'));
31
- this.world.runtime[exports.WEBSERVER] = this.webserver;
32
- this.world.runtime[exports.CHECK_LISTENER] = WebServerStepper.checkListener;
49
+ // this.world.runtime[CHECK_LISTENER] = WebServerStepper.checkListener;
50
+ const port = util_1.getStepperOption(this, 'PORT', this.world.options);
51
+ this.webserver = new server_express_1.ServerExpress(this.world.logger, [process.cwd(), 'files'].join('/'), port);
52
+ this.world.runtime[defs_2.WEBSERVER] = this.webserver;
33
53
  }
34
54
  async close() {
35
55
  await this.webserver?.close();
36
56
  }
37
- static async checkListener(options, webserver) {
38
- const port = options[`HAIBUN_O_${exports.WEBSERVER_STEPPER.toUpperCase()}_PORT`];
39
- await webserver.listening(port || server_express_1.DEFAULT_PORT);
40
- }
41
57
  };
42
58
  exports.default = WebServerStepper;
43
59
  //# sourceMappingURL=web-server-stepper.js.map
@@ -1 +1 @@
1
- {"version":3,"file":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C,IAAI,CAAC,GAAG,CAAC,EAAE,IAAI,CAAC,CAAC;QAChG,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,gBAAS,CAAC,GAAG,IAAI,CAAC,SAAS,CAAC;IACjD,CAAC;IAED,KAAK,CAAC,KAAK;QACT,MAAM,IAAI,CAAC,SAAS,EAAE,KAAK,EAAE,CAAC;IAChC,CAAC;CAiCF,CAAC;AACF,kBAAe,gBAAgB,CAAC"}
@@ -1,59 +1,31 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
- }) : (function(o, m, k, k2) {
6
- if (k2 === undefined) k2 = k;
7
- o[k2] = m[k];
8
- }));
9
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
- Object.defineProperty(o, "default", { enumerable: true, value: v });
11
- }) : function(o, v) {
12
- o["default"] = v;
13
- });
14
- var __importStar = (this && this.__importStar) || function (mod) {
15
- if (mod && mod.__esModule) return mod;
16
- var result = {};
17
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18
- __setModuleDefault(result, mod);
19
- return result;
20
- };
21
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
22
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
23
4
  };
24
5
  Object.defineProperty(exports, "__esModule", { value: true });
25
- const node_fetch_1 = __importDefault(require("node-fetch"));
26
- const Executor_1 = require("@haibun/core/build/lib/Executor");
27
- const util_1 = require("@haibun/core/build/lib/util");
28
- const TestSteps_1 = require("@haibun/core/build/lib/TestSteps");
29
- const web_server_stepper_1 = __importStar(require("./web-server-stepper"));
30
- const serverLoc = [process.cwd(), 'build', 'web-server-stepper'].join('/');
6
+ const lib_1 = require("@haibun/core/build/lib/test/lib");
7
+ const web_http_1 = __importDefault(require("@haibun/web-http/build/web-http"));
8
+ const web_server_stepper_1 = __importDefault(require("./web-server-stepper"));
31
9
  describe('static mount', () => {
32
- it('listens on serve files', async () => {
33
- const { world, vstep, steppers } = await TestSteps_1.getTestEnv([serverLoc], 'serve files from test', util_1.getDefaultWorld().world);
34
- const res = await Executor_1.Executor.doFeatureStep(vstep, world);
35
- expect(res.ok).toBe(true);
36
- const server = util_1.getStepper(steppers, web_server_stepper_1.WEBSERVER_STEPPER);
37
- expect(server.webserver).toBeDefined();
38
- const content = await node_fetch_1.default('http://localhost:8123/testfile');
39
- expect(await content.text()).toEqual('content');
40
- await server.close();
10
+ it('serves files', async () => {
11
+ const feature = { path: '/features/test.feature', content: `serve files from test\nfetch from http://localhost:8123/testfile is "content"` };
12
+ const { result } = await lib_1.testWithDefaults([feature], [web_server_stepper_1.default, web_http_1.default]);
13
+ expect(result.ok).toBe(true);
41
14
  });
42
15
  it('restricts characters used in static mount folder name', async () => {
43
- const { world, vstep, steppers } = await TestSteps_1.getTestEnv([serverLoc], 'serve files from l*(*$**', util_1.getDefaultWorld().world);
44
- const res = await Executor_1.Executor.doFeatureStep(vstep, world);
45
- expect(res.ok).toBe(false);
46
- util_1.getStepper(steppers, web_server_stepper_1.WEBSERVER_STEPPER).close();
16
+ const feature = { path: '/features/test.feature', content: `serve files from l*(*$\n` };
17
+ const { result } = await lib_1.testWithDefaults([feature], [web_server_stepper_1.default]);
18
+ expect(result.ok).toBe(false);
47
19
  });
48
20
  it("doesn't re-mount same static mount", async () => {
49
- const { result, steppers } = await TestSteps_1.testRun('/test/static-no-remount', [web_server_stepper_1.default], util_1.getDefaultWorld().world);
21
+ const feature = { path: '/features/test.feature', content: `serve files from test\nserve files from test\n` };
22
+ const { result } = await lib_1.testWithDefaults([feature], [web_server_stepper_1.default]);
50
23
  expect(result.ok).toBe(true);
51
- util_1.getStepper(steppers, web_server_stepper_1.WEBSERVER_STEPPER).close();
52
24
  });
53
25
  it("doesn't permit different static mount", async () => {
54
- const { result, steppers } = await TestSteps_1.testRun('/test/static-fails', [web_server_stepper_1.default], util_1.getDefaultWorld().world);
26
+ const feature = { path: '/features/test.feature', content: `serve files from test\nserve files from fails\n` };
27
+ const { result } = await lib_1.testWithDefaults([feature], [web_server_stepper_1.default]);
55
28
  expect(result.ok).toBe(false);
56
- util_1.getStepper(steppers, web_server_stepper_1.WEBSERVER_STEPPER).close();
57
29
  });
58
30
  });
59
31
  //# sourceMappingURL=web-server-stepper.test.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"web-server-stepper.test.js","sourceRoot":"","sources":["../src/web-server-stepper.test.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAAA,4DAA+B;AAE/B,8DAA2D;AAC3D,sDAA0E;AAC1E,gEAAuE;AAEvE,2EAAoF;AAEpF,MAAM,SAAS,GAAG,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,OAAO,EAAE,oBAAoB,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAE3E,QAAQ,CAAC,cAAc,EAAE,GAAG,EAAE;IAC5B,EAAE,CAAC,wBAAwB,EAAE,KAAK,IAAI,EAAE;QACtC,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAE,GAAG,MAAM,sBAAU,CAAC,CAAC,SAAS,CAAC,EAAE,uBAAuB,EAAE,sBAAe,EAAE,CAAC,KAAK,CAAC,CAAC;QACnH,MAAM,GAAG,GAAG,MAAM,mBAAQ,CAAC,aAAa,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;QAEvD,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAC1B,MAAM,MAAM,GAAsB,iBAAU,CAAC,QAAQ,EAAE,sCAAiB,CAAC,CAAC;QAE1E,MAAM,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,WAAW,EAAE,CAAC;QACvC,MAAM,OAAO,GAAG,MAAM,oBAAK,CAAC,gCAAgC,CAAC,CAAC;QA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G,MAAM,sBAAgB,CAAC,CAAC,OAAO,CAAC,EAAE,CAAC,4BAAM,CAAC,CAAC,CAAC;QAE/D,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC/B,CAAC,CAAC,CAAC;IACH,EAAE,CAAC,uCAAuC,EAAE,KAAK,IAAI,EAAE;QACrD,MAAM,OAAO,GAAG,EAAE,IAAI,EAAE,wBAAwB,EAAE,OAAO,EAAE,iDAAiD,EAAE,CAAA;QAC9G,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM,sBAAgB,CAAC,CAAC,OAAO,CAAC,EAAE,CAAC,4BAAM,CAAC,CAAC,CAAC;QAE/D,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAChC,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@haibun/web-server-express",
3
- "version": "0.2.1",
3
+ "version": "1.1.1",
4
4
  "description": "",
5
5
  "main": "build/web-server-stepper.js",
6
6
  "files": [
@@ -15,9 +15,9 @@
15
15
  "author": "",
16
16
  "license": "ISC",
17
17
  "dependencies": {
18
- "@types/node-fetch": "^2.5.10",
19
- "express": "^4.17.1",
20
- "node-fetch": "^2.6.1"
18
+ "@types/cookie-parser": "^1.4.2",
19
+ "cookie-parser": "^1.4.5",
20
+ "express": "^4.17.1"
21
21
  },
22
22
  "devDependencies": {
23
23
  "@types/express": "^4.17.12",