@celljs/express-adapter 3.8.0 → 4.0.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/esm/node/context.d.ts +4 -0
- package/esm/node/context.js +5 -0
- package/esm/node/context.js.map +1 -0
- package/esm/node/http-application-entry.d.ts +1 -0
- package/esm/node/http-application-entry.js +45 -0
- package/esm/node/http-application-entry.js.map +1 -0
- package/esm/node/index.d.ts +1 -0
- package/esm/node/index.js +2 -0
- package/esm/node/index.js.map +1 -0
- package/esm/node/module.d.ts +2 -0
- package/esm/node/module.js +3 -0
- package/esm/node/module.js.map +1 -0
- package/esm/package.json +3 -0
- package/lib/node/context.d.ts +1 -0
- package/lib/node/context.d.ts.map +1 -1
- package/lib/node/context.js +2 -1
- package/lib/node/context.js.map +1 -1
- package/lib/node/http-application-entry.js +25 -8
- package/lib/node/http-application-entry.js.map +1 -1
- package/package.json +37 -7
- package/src/node/context.ts +2 -1
- package/src/node/http-application-entry.ts +26 -8
- package/cell.yml +0 -2
|
@@ -0,0 +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;IACV,IAAI,EAAE,WAAW;CACpB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { container } from '@celljs/core/lib/common/container/dynamic-container';
|
|
2
|
+
import { Application } from '@celljs/core/lib/common/application/application-protocol';
|
|
3
|
+
import { ApplicationHost } from '@celljs/core/lib/common/application/application-host';
|
|
4
|
+
import { ContainerProvider } from '@celljs/core/lib/common/container/container-provider';
|
|
5
|
+
import { Dispatcher } from '@celljs/web/lib/node/dispatcher/dispatcher-protocol';
|
|
6
|
+
import { Context } from '@celljs/web/lib/node/context';
|
|
7
|
+
import { ServerAware } from '@celljs/web/lib/node/http';
|
|
8
|
+
import { ConfigProvider } from '@celljs/core/lib/common/config/config-protocol';
|
|
9
|
+
import express from 'express';
|
|
10
|
+
import { DEFAULT_SERVER_OPTIONS } from './context.js';
|
|
11
|
+
const host = ApplicationHost.get();
|
|
12
|
+
container.then(async (c) => {
|
|
13
|
+
var _a;
|
|
14
|
+
ContainerProvider.set(c);
|
|
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();
|
|
18
|
+
const app = express();
|
|
19
|
+
app.all('*', async (req, res) => {
|
|
20
|
+
const dispatcher = c.get(Dispatcher);
|
|
21
|
+
const httpContext = new Context(req, res);
|
|
22
|
+
Context.run(() => dispatcher.dispatch(httpContext));
|
|
23
|
+
});
|
|
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
|
+
}
|
|
30
|
+
}
|
|
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);
|
|
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
|
+
}
|
|
45
|
+
//# sourceMappingURL=http-application-entry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1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B,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './context.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/node/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"module.js","sourceRoot":"","sources":["../../src/node/module.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAExC,eAAe,QAAQ,EAAE,CAAC"}
|
package/esm/package.json
ADDED
package/lib/node/context.d.ts
CHANGED
|
@@ -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"}
|
package/lib/node/context.js
CHANGED
package/lib/node/context.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context.js","sourceRoot":"","sources":["../../src/node/context.ts"],"names":[],"mappings":";;;AAAa,QAAA,sBAAsB,GAAG;IAClC,IAAI,EAAE,IAAI;
|
|
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
|
|
18
|
-
const
|
|
19
|
-
|
|
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
|
-
|
|
27
|
-
const
|
|
28
|
-
|
|
29
|
-
|
|
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
|
-
|
|
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
|
|
1
|
+
{"version":3,"file":"http-application-entry.js","sourceRoot":"","sources":["../../src/node/http-application-entry.ts"],"names":[],"mappings":";;;;;AAAA,2FAAgF;AAChF,mGAAuF;AACvF,2FAAuF;AACvF,6FAAyF;AACzF,6FAAiF;AACjF,0DAAuD;AACvD,oDAAwD;AACxD,oFAAgF;AAEhF,sDAA8B;AAC9B,uCAAmD;AAEnD,MAAM,IAAI,GAAG,kCAAe,CAAC,GAAG,EAAE,CAAC;AAEnC,6BAAS,CAAC,IAAI,CAAC,KAAK,EAAC,CAAC,EAAC,EAAE;;IACrB,sCAAiB,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;IACzB,OAAM,MAAA,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,WAAW,+CAAjB,IAAI,CAAiB,CAAA,CAAC;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vB,CAAC,CAAC,CAAC;AAEH,SAAS,WAAW,CAAC,GAAoB,EAAE,cAA8B;IACrE,4FAA4F;IAC5F,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,QAAQ,EAAE,GAAG,EAAE,GAAG,gCAAsB,EAAE,GAAG,cAAc,CAAC,GAAG,CAAM,aAAa,EAAE,EAAE,CAAC,EAAE,CAAC;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
|
+
"version": "4.0.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cell-component"
|
|
@@ -18,22 +18,52 @@
|
|
|
18
18
|
"typings": "lib/node/index.d.ts",
|
|
19
19
|
"files": [
|
|
20
20
|
"lib",
|
|
21
|
-
"
|
|
22
|
-
"
|
|
21
|
+
"esm",
|
|
22
|
+
"src"
|
|
23
23
|
],
|
|
24
24
|
"scripts": {
|
|
25
|
-
"build": "tsc -b",
|
|
26
|
-
"clean": "rm -rf lib *.tsbuildinfo",
|
|
25
|
+
"build": "tsc -b && bun ../../scripts/build-esm.ts",
|
|
26
|
+
"clean": "rm -rf lib esm *.tsbuildinfo",
|
|
27
27
|
"test": "bun test --preload reflect-metadata ./lib",
|
|
28
28
|
"watch": "tsc -b -w --preserveWatchOutput"
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@celljs/core": "
|
|
32
|
-
"@celljs/web": "
|
|
31
|
+
"@celljs/core": "4.0.0",
|
|
32
|
+
"@celljs/web": "4.0.0",
|
|
33
33
|
"express": "^4.17.1",
|
|
34
34
|
"tslib": "^2.8.0"
|
|
35
35
|
},
|
|
36
36
|
"publishConfig": {
|
|
37
37
|
"access": "public"
|
|
38
|
+
},
|
|
39
|
+
"exports": {
|
|
40
|
+
".": {
|
|
41
|
+
"import": "./esm/node/index.js",
|
|
42
|
+
"default": "./lib/node/index.js"
|
|
43
|
+
},
|
|
44
|
+
"./package.json": "./package.json",
|
|
45
|
+
"./lib/node": {
|
|
46
|
+
"import": "./esm/node/index.js",
|
|
47
|
+
"default": "./lib/node/index.js"
|
|
48
|
+
},
|
|
49
|
+
"./lib/*.js": {
|
|
50
|
+
"import": "./esm/*.js",
|
|
51
|
+
"default": "./lib/*.js"
|
|
52
|
+
},
|
|
53
|
+
"./lib/*": {
|
|
54
|
+
"import": "./esm/*.js",
|
|
55
|
+
"default": "./lib/*.js"
|
|
56
|
+
},
|
|
57
|
+
"./*": "./*"
|
|
58
|
+
},
|
|
59
|
+
"cell": {
|
|
60
|
+
"modules": {
|
|
61
|
+
"backend": [
|
|
62
|
+
"lib/node/module"
|
|
63
|
+
]
|
|
64
|
+
},
|
|
65
|
+
"entries": {
|
|
66
|
+
"http": "lib/node/http-application-entry"
|
|
67
|
+
}
|
|
38
68
|
}
|
|
39
69
|
}
|
package/src/node/context.ts
CHANGED
|
@@ -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
|
|
15
|
-
const
|
|
16
|
-
|
|
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
|
-
|
|
24
|
-
const
|
|
25
|
-
|
|
26
|
-
|
|
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
|
-
|
|
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