@celljs/express-adapter 3.9.0 → 4.1.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.
@@ -1,3 +1,4 @@
1
1
  export declare const DEFAULT_SERVER_OPTIONS: {
2
2
  port: number;
3
+ host: string;
3
4
  };
@@ -1,4 +1,5 @@
1
1
  export const DEFAULT_SERVER_OPTIONS = {
2
- port: 3000
2
+ port: 3000,
3
+ host: '127.0.0.1'
3
4
  };
4
5
  //# sourceMappingURL=context.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"context.js","sourceRoot":"","sources":["../../src/node/context.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,sBAAsB,GAAG;IAClC,IAAI,EAAE,IAAI;CACb,CAAC"}
1
+ {"version":3,"file":"context.js","sourceRoot":"","sources":["../../src/node/context.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,sBAAsB,GAAG;IAClC,IAAI,EAAE,IAAI;IACV,IAAI,EAAE,WAAW;CACpB,CAAC"}
@@ -1,5 +1,6 @@
1
1
  import { container } from '@celljs/core/lib/common/container/dynamic-container';
2
2
  import { Application } from '@celljs/core/lib/common/application/application-protocol';
3
+ import { ApplicationHost } from '@celljs/core/lib/common/application/application-host';
3
4
  import { ContainerProvider } from '@celljs/core/lib/common/container/container-provider';
4
5
  import { Dispatcher } from '@celljs/web/lib/node/dispatcher/dispatcher-protocol';
5
6
  import { Context } from '@celljs/web/lib/node/context';
@@ -7,22 +8,38 @@ import { ServerAware } from '@celljs/web/lib/node/http';
7
8
  import { ConfigProvider } from '@celljs/core/lib/common/config/config-protocol';
8
9
  import express from 'express';
9
10
  import { DEFAULT_SERVER_OPTIONS } from './context.js';
11
+ const host = ApplicationHost.get();
10
12
  container.then(async (c) => {
13
+ var _a;
11
14
  ContainerProvider.set(c);
12
- await c.get(Application).start();
13
- const configProvider = c.get(ConfigProvider);
14
- const port = parseInt(process.env.SERVER__PORT || '') || configProvider.get('cell.server', DEFAULT_SERVER_OPTIONS).port;
15
+ await ((_a = host === null || host === void 0 ? void 0 : host.beforeStart) === null || _a === void 0 ? void 0 : _a.call(host));
16
+ const application = c.get(Application);
17
+ await application.start();
15
18
  const app = express();
16
19
  app.all('*', async (req, res) => {
17
20
  const dispatcher = c.get(Dispatcher);
18
21
  const httpContext = new Context(req, res);
19
22
  Context.run(() => dispatcher.dispatch(httpContext));
20
23
  });
21
- const server = app.listen(port, process.env.SERVER__HOST || '127.0.0.1');
22
- const items = c.getAll(ServerAware);
23
- for (const serverAware of items) {
24
- await serverAware.setServer(server);
24
+ // In-process hosts (cell dev, tests) serve the handler themselves.
25
+ const server = host ? host.server : startServer(app, c.get(ConfigProvider));
26
+ if (server) {
27
+ for (const serverAware of c.getAll(ServerAware)) {
28
+ await serverAware.setServer(server);
29
+ }
25
30
  }
26
- console.log(`serve ${port}`);
31
+ host === null || host === void 0 ? void 0 : host.started({ container: c, handler: app, stop: () => application.stop() });
32
+ }).catch(error => {
33
+ if (!host) {
34
+ throw error;
35
+ }
36
+ host.failed(error);
27
37
  });
38
+ function startServer(app, configProvider) {
39
+ // Override with CELL_BACKEND__SERVER__PORT / CELL_BACKEND__SERVER__HOST like any other key.
40
+ const { port, host: hostname } = { ...DEFAULT_SERVER_OPTIONS, ...configProvider.get('cell.server', {}) };
41
+ const server = app.listen(port, hostname);
42
+ console.log(`serve ${port}`);
43
+ return server;
44
+ }
28
45
  //# sourceMappingURL=http-application-entry.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"http-application-entry.js","sourceRoot":"","sources":["../../src/node/http-application-entry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,qDAAqD,CAAC;AAChF,OAAO,EAAE,WAAW,EAAE,MAAM,0DAA0D,CAAC;AACvF,OAAO,EAAE,iBAAiB,EAAE,MAAM,sDAAsD,CAAC;AACzF,OAAO,EAAE,UAAU,EAAE,MAAM,qDAAqD,CAAC;AACjF,OAAO,EAAE,OA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AC;IAC9G,MAAM,MAAM,GAAG,GAAG,CAAC,MAAM,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;IAC1C,OAAO,CAAC,GAAG,CAAC,SAAS,IAAI,EAAE,CAAC,CAAC;IAC7B,OAAO,MAAM,CAAC;AAClB,CAAC"}
@@ -1,4 +1,5 @@
1
1
  export declare const DEFAULT_SERVER_OPTIONS: {
2
2
  port: number;
3
+ host: string;
3
4
  };
4
5
  //# sourceMappingURL=context.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../src/node/context.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,sBAAsB;IAC/B,IAAI;CACP,CAAC"}
1
+ {"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../src/node/context.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,sBAAsB;IAC/B,IAAI;IACJ,IAAI;CACP,CAAC"}
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.DEFAULT_SERVER_OPTIONS = void 0;
4
4
  exports.DEFAULT_SERVER_OPTIONS = {
5
- port: 3000
5
+ port: 3000,
6
+ host: '127.0.0.1'
6
7
  };
7
8
  //# sourceMappingURL=context.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"context.js","sourceRoot":"","sources":["../../src/node/context.ts"],"names":[],"mappings":";;;AAAa,QAAA,sBAAsB,GAAG;IAClC,IAAI,EAAE,IAAI;CACb,CAAC"}
1
+ {"version":3,"file":"context.js","sourceRoot":"","sources":["../../src/node/context.ts"],"names":[],"mappings":";;;AAAa,QAAA,sBAAsB,GAAG;IAClC,IAAI,EAAE,IAAI;IACV,IAAI,EAAE,WAAW;CACpB,CAAC"}
@@ -5,6 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const dynamic_container_1 = require("@celljs/core/lib/common/container/dynamic-container");
7
7
  const application_protocol_1 = require("@celljs/core/lib/common/application/application-protocol");
8
+ const application_host_1 = require("@celljs/core/lib/common/application/application-host");
8
9
  const container_provider_1 = require("@celljs/core/lib/common/container/container-provider");
9
10
  const dispatcher_protocol_1 = require("@celljs/web/lib/node/dispatcher/dispatcher-protocol");
10
11
  const context_1 = require("@celljs/web/lib/node/context");
@@ -12,22 +13,38 @@ const http_1 = require("@celljs/web/lib/node/http");
12
13
  const config_protocol_1 = require("@celljs/core/lib/common/config/config-protocol");
13
14
  const express_1 = __importDefault(require("express"));
14
15
  const context_2 = require("./context");
16
+ const host = application_host_1.ApplicationHost.get();
15
17
  dynamic_container_1.container.then(async (c) => {
18
+ var _a;
16
19
  container_provider_1.ContainerProvider.set(c);
17
- await c.get(application_protocol_1.Application).start();
18
- const configProvider = c.get(config_protocol_1.ConfigProvider);
19
- const port = parseInt(process.env.SERVER__PORT || '') || configProvider.get('cell.server', context_2.DEFAULT_SERVER_OPTIONS).port;
20
+ await ((_a = host === null || host === void 0 ? void 0 : host.beforeStart) === null || _a === void 0 ? void 0 : _a.call(host));
21
+ const application = c.get(application_protocol_1.Application);
22
+ await application.start();
20
23
  const app = (0, express_1.default)();
21
24
  app.all('*', async (req, res) => {
22
25
  const dispatcher = c.get(dispatcher_protocol_1.Dispatcher);
23
26
  const httpContext = new context_1.Context(req, res);
24
27
  context_1.Context.run(() => dispatcher.dispatch(httpContext));
25
28
  });
26
- const server = app.listen(port, process.env.SERVER__HOST || '127.0.0.1');
27
- const items = c.getAll(http_1.ServerAware);
28
- for (const serverAware of items) {
29
- await serverAware.setServer(server);
29
+ // In-process hosts (cell dev, tests) serve the handler themselves.
30
+ const server = host ? host.server : startServer(app, c.get(config_protocol_1.ConfigProvider));
31
+ if (server) {
32
+ for (const serverAware of c.getAll(http_1.ServerAware)) {
33
+ await serverAware.setServer(server);
34
+ }
30
35
  }
31
- console.log(`serve ${port}`);
36
+ host === null || host === void 0 ? void 0 : host.started({ container: c, handler: app, stop: () => application.stop() });
37
+ }).catch(error => {
38
+ if (!host) {
39
+ throw error;
40
+ }
41
+ host.failed(error);
32
42
  });
43
+ function startServer(app, configProvider) {
44
+ // Override with CELL_BACKEND__SERVER__PORT / CELL_BACKEND__SERVER__HOST like any other key.
45
+ const { port, host: hostname } = { ...context_2.DEFAULT_SERVER_OPTIONS, ...configProvider.get('cell.server', {}) };
46
+ const server = app.listen(port, hostname);
47
+ console.log(`serve ${port}`);
48
+ return server;
49
+ }
33
50
  //# sourceMappingURL=http-application-entry.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"http-application-entry.js","sourceRoot":"","sources":["../../src/node/http-application-entry.ts"],"names":[],"mappings":";;;;;AAAA,2FAAgF;AAChF,mGAAuF;AACvF,6FAAyF;AACzF,6FAAiF;AACjF,0DAAuD;AACvD,oDAAwD;AACxD,oFAAgF;AAEhF,sDAA8B;AAC9B,uCAAmD;AAEnD,6BAAS,CAAC,IAAI,CAAC,KAAK,EAAC,CAAC,EAAC,EAAE;IACrB,sCAAiB,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;IACzB,MAAM,CAAC,CAAC,GAAG,CAAc,kCAAW,CAAC,CAAC,KAAK,EAAE,CAAC;IAC9C,MAAM,cAAc,GAAG,CAAC,CAAC,GAAG,CAAiB,gCAAc,CAAC,CAAC;IAC7D,MAAM,IAAI,GAAG,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,YAAY,IAAI,EAAE,CAAC,IAAI,cAAc,CAAC,GAAG,CAAM,aAAa,EAAE,gCAAsB,CAAC,CAAC,IAAI,CAAC;IAC7H,MAAM,GAAG,GAAG,IAAA,iBAAO,GAAE,CAAC;IACtB,GAAG,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,EAAE,GAAQ,EAAE,GAAQ,EAAE,EAAE;QACtC,MAAM,UAAU,GAAG,CAAC,CAAC,GAAG,CAAsB,gCAAU,CAAC,CAAC;QAC1D,MAAM,WAAW,GAAG,IAAI,iBAAO,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;QAC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C;IAC9G,MAAM,MAAM,GAAG,GAAG,CAAC,MAAM,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;IAC1C,OAAO,CAAC,GAAG,CAAC,SAAS,IAAI,EAAE,CAAC,CAAC;IAC7B,OAAO,MAAM,CAAC;AAClB,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@celljs/express-adapter",
3
- "version": "3.9.0",
3
+ "version": "4.1.0",
4
4
  "description": "",
5
5
  "keywords": [
6
6
  "cell-component"
@@ -19,8 +19,7 @@
19
19
  "files": [
20
20
  "lib",
21
21
  "esm",
22
- "src",
23
- "cell.yml"
22
+ "src"
24
23
  ],
25
24
  "scripts": {
26
25
  "build": "tsc -b && bun ../../scripts/build-esm.ts",
@@ -29,36 +28,41 @@
29
28
  "watch": "tsc -b -w --preserveWatchOutput"
30
29
  },
31
30
  "dependencies": {
32
- "@celljs/core": "3.9.0",
33
- "@celljs/web": "3.9.0",
34
- "express": "^4.17.1",
35
- "tslib": "^2.8.0"
31
+ "@celljs/core": "4.1.0",
32
+ "@celljs/web": "4.1.0",
33
+ "express": "^4.22.3"
36
34
  },
37
35
  "publishConfig": {
38
36
  "access": "public"
39
37
  },
40
38
  "exports": {
41
39
  ".": {
42
- "webpack": "./lib/node/index.js",
43
40
  "import": "./esm/node/index.js",
44
41
  "default": "./lib/node/index.js"
45
42
  },
46
43
  "./package.json": "./package.json",
47
44
  "./lib/node": {
48
- "webpack": "./lib/node/index.js",
49
45
  "import": "./esm/node/index.js",
50
46
  "default": "./lib/node/index.js"
51
47
  },
52
48
  "./lib/*.js": {
53
- "webpack": "./lib/*.js",
54
49
  "import": "./esm/*.js",
55
50
  "default": "./lib/*.js"
56
51
  },
57
52
  "./lib/*": {
58
- "webpack": "./lib/*.js",
59
53
  "import": "./esm/*.js",
60
54
  "default": "./lib/*.js"
61
55
  },
62
56
  "./*": "./*"
57
+ },
58
+ "cell": {
59
+ "modules": {
60
+ "backend": [
61
+ "lib/node/module"
62
+ ]
63
+ },
64
+ "entries": {
65
+ "http": "lib/node/http-application-entry"
66
+ }
63
67
  }
64
68
  }
@@ -1,3 +1,4 @@
1
1
  export const DEFAULT_SERVER_OPTIONS = {
2
- port: 3000
2
+ port: 3000,
3
+ host: '127.0.0.1'
3
4
  };
@@ -1,5 +1,6 @@
1
1
  import { container } from '@celljs/core/lib/common/container/dynamic-container';
2
2
  import { Application } from '@celljs/core/lib/common/application/application-protocol';
3
+ import { ApplicationHost } from '@celljs/core/lib/common/application/application-host';
3
4
  import { ContainerProvider } from '@celljs/core/lib/common/container/container-provider';
4
5
  import { Dispatcher } from '@celljs/web/lib/node/dispatcher/dispatcher-protocol';
5
6
  import { Context } from '@celljs/web/lib/node/context';
@@ -9,21 +10,38 @@ import { ConfigProvider } from '@celljs/core/lib/common/config/config-protocol';
9
10
  import express from 'express';
10
11
  import { DEFAULT_SERVER_OPTIONS } from './context';
11
12
 
13
+ const host = ApplicationHost.get();
14
+
12
15
  container.then(async c => {
13
16
  ContainerProvider.set(c);
14
- await c.get<Application>(Application).start();
15
- const configProvider = c.get<ConfigProvider>(ConfigProvider);
16
- const port = parseInt(process.env.SERVER__PORT || '') || configProvider.get<any>('cell.server', DEFAULT_SERVER_OPTIONS).port;
17
+ await host?.beforeStart?.();
18
+ const application = c.get<Application>(Application);
19
+ await application.start();
17
20
  const app = express();
18
21
  app.all('*', async (req: any, res: any) => {
19
22
  const dispatcher = c.get<Dispatcher<Context>>(Dispatcher);
20
23
  const httpContext = new Context(req, res);
21
24
  Context.run(() => dispatcher.dispatch(httpContext));
22
25
  });
23
- const server = app.listen(port, process.env.SERVER__HOST || '127.0.0.1');
24
- const items = c.getAll<ServerAware>(ServerAware);
25
- for (const serverAware of items) {
26
- await serverAware.setServer(server);
26
+ // In-process hosts (cell dev, tests) serve the handler themselves.
27
+ const server = host ? host.server : startServer(app, c.get<ConfigProvider>(ConfigProvider));
28
+ if (server) {
29
+ for (const serverAware of c.getAll<ServerAware>(ServerAware)) {
30
+ await serverAware.setServer(server as any);
31
+ }
27
32
  }
28
- console.log(`serve ${port}`);
33
+ host?.started({ container: c, handler: app, stop: () => application.stop() });
34
+ }).catch(error => {
35
+ if (!host) {
36
+ throw error;
37
+ }
38
+ host.failed(error);
29
39
  });
40
+
41
+ function startServer(app: express.Express, configProvider: ConfigProvider) {
42
+ // Override with CELL_BACKEND__SERVER__PORT / CELL_BACKEND__SERVER__HOST like any other key.
43
+ const { port, host: hostname } = { ...DEFAULT_SERVER_OPTIONS, ...configProvider.get<any>('cell.server', {}) };
44
+ const server = app.listen(port, hostname);
45
+ console.log(`serve ${port}`);
46
+ return server;
47
+ }
package/cell.yml DELETED
@@ -1,2 +0,0 @@
1
- backend:
2
- entry: lib/node/http-application-entry