@itwin/express-server 5.0.0-dev.9 → 5.0.0-dev.92
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/CHANGELOG.md +51 -1
- package/lib/cjs/ExpressServer.js +7 -5
- package/lib/cjs/ExpressServer.js.map +1 -1
- package/lib/esm/ExpressServer.d.ts +42 -0
- package/lib/esm/ExpressServer.d.ts.map +1 -0
- package/lib/esm/ExpressServer.js +80 -0
- package/lib/esm/ExpressServer.js.map +1 -0
- package/package.json +15 -13
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,56 @@
|
|
|
1
1
|
# Change Log - @itwin/express-server
|
|
2
2
|
|
|
3
|
-
This log was last generated on
|
|
3
|
+
This log was last generated on Wed, 19 Mar 2025 15:33:24 GMT and should not be manually modified.
|
|
4
|
+
|
|
5
|
+
## 4.10.11
|
|
6
|
+
Wed, 19 Mar 2025 15:30:39 GMT
|
|
7
|
+
|
|
8
|
+
_Version update only_
|
|
9
|
+
|
|
10
|
+
## 4.10.10
|
|
11
|
+
Tue, 11 Mar 2025 15:25:11 GMT
|
|
12
|
+
|
|
13
|
+
_Version update only_
|
|
14
|
+
|
|
15
|
+
## 4.10.9
|
|
16
|
+
Tue, 11 Mar 2025 05:17:33 GMT
|
|
17
|
+
|
|
18
|
+
_Version update only_
|
|
19
|
+
|
|
20
|
+
## 4.10.8
|
|
21
|
+
Thu, 06 Mar 2025 14:13:37 GMT
|
|
22
|
+
|
|
23
|
+
_Version update only_
|
|
24
|
+
|
|
25
|
+
## 4.10.7
|
|
26
|
+
Tue, 18 Feb 2025 17:27:03 GMT
|
|
27
|
+
|
|
28
|
+
_Version update only_
|
|
29
|
+
|
|
30
|
+
## 4.10.6
|
|
31
|
+
Fri, 24 Jan 2025 08:02:40 GMT
|
|
32
|
+
|
|
33
|
+
_Version update only_
|
|
34
|
+
|
|
35
|
+
## 4.10.5
|
|
36
|
+
Tue, 21 Jan 2025 21:56:45 GMT
|
|
37
|
+
|
|
38
|
+
_Version update only_
|
|
39
|
+
|
|
40
|
+
## 4.10.4
|
|
41
|
+
Mon, 13 Jan 2025 14:06:43 GMT
|
|
42
|
+
|
|
43
|
+
_Version update only_
|
|
44
|
+
|
|
45
|
+
## 4.10.3
|
|
46
|
+
Mon, 06 Jan 2025 14:00:13 GMT
|
|
47
|
+
|
|
48
|
+
_Version update only_
|
|
49
|
+
|
|
50
|
+
## 4.10.2
|
|
51
|
+
Thu, 21 Nov 2024 15:22:20 GMT
|
|
52
|
+
|
|
53
|
+
_Version update only_
|
|
4
54
|
|
|
5
55
|
## 4.10.1
|
|
6
56
|
Thu, 14 Nov 2024 18:11:00 GMT
|
package/lib/cjs/ExpressServer.js
CHANGED
|
@@ -17,10 +17,16 @@ const core_backend_1 = require("@itwin/core-backend");
|
|
|
17
17
|
* @public
|
|
18
18
|
*/
|
|
19
19
|
class IModelJsExpressServer {
|
|
20
|
+
/** The default configuration for servers. */
|
|
21
|
+
static defaults = {
|
|
22
|
+
uploadLimit: "5mb",
|
|
23
|
+
};
|
|
24
|
+
_protocol;
|
|
25
|
+
_config;
|
|
26
|
+
_app = express();
|
|
20
27
|
/** @alpha */
|
|
21
28
|
get rpcConfiguration() { return this._protocol.configuration; }
|
|
22
29
|
constructor(protocol, config = IModelJsExpressServer.defaults) {
|
|
23
|
-
this._app = express();
|
|
24
30
|
this._protocol = protocol;
|
|
25
31
|
this._config = config;
|
|
26
32
|
}
|
|
@@ -62,10 +68,6 @@ class IModelJsExpressServer {
|
|
|
62
68
|
}
|
|
63
69
|
}
|
|
64
70
|
exports.IModelJsExpressServer = IModelJsExpressServer;
|
|
65
|
-
/** The default configuration for servers. */
|
|
66
|
-
IModelJsExpressServer.defaults = {
|
|
67
|
-
uploadLimit: "5mb",
|
|
68
|
-
};
|
|
69
71
|
/**
|
|
70
72
|
* @alpha
|
|
71
73
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ExpressServer.js","sourceRoot":"","sources":["../../src/ExpressServer.ts"],"names":[],"mappings":";;;AAAA;;;+FAG+F;AAC/F,mCAAmC;AACnC,uCAAuC;AAEvC,oDAAuG;AACvG,sDAAuD;AAUvD;;;;;;GAMG;AACH,MAAa,qBAAqB;
|
|
1
|
+
{"version":3,"file":"ExpressServer.js","sourceRoot":"","sources":["../../src/ExpressServer.ts"],"names":[],"mappings":";;;AAAA;;;+FAG+F;AAC/F,mCAAmC;AACnC,uCAAuC;AAEvC,oDAAuG;AACvG,sDAAuD;AAUvD;;;;;;GAMG;AACH,MAAa,qBAAqB;IAChC,6CAA6C;IACtC,MAAM,CAAU,QAAQ,GAAgC;QAC7D,WAAW,EAAE,KAAK;KACnB,CAAC;IAEM,SAAS,CAAoB;IAC7B,OAAO,CAA8B;IACnC,IAAI,GAAkC,OAAO,EAAE,CAAC;IAE1D,aAAa;IACb,IAAW,gBAAgB,KAAuB,OAAO,IAAI,CAAC,SAAS,CAAC,aAAa,CAAC,CAAC,CAAC;IAExF,YAAY,QAA2B,EAAE,MAAM,GAAG,qBAAqB,CAAC,QAAQ;QAC9E,IAAI,CAAC,SAAS,GAAG,QAAQ,CAAC;QAC1B,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;IACxB,CAAC;IAES,oBAAoB;QAC5B,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,IAAI,CAAC,OAAO,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC;QACjE,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,KAAK,EAAE,IAAI,CAAC,OAAO,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC;IAClE,CAAC;IAES,iBAAiB;QACzB,2BAA2B;QAC3B,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,EAAE,CAAC,IAAI,EAAE,GAAG,EAAE,IAAI,EAAE,EAAE;YACvC,GAAG,CAAC,MAAM,CA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,KAAK,CAAC,UAAU,CAAC,IAAqB;QAC3C,IAAI,CAAC,oBAAoB,EAAE,CAAC;QAC5B,IAAI,CAAC,iBAAiB,EAAE,CAAC;QACzB,IAAI,CAAC,gBAAgB,EAAE,CAAC;QAExB,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;QAC5B,OAAO,IAAI,OAAO,CAAa,CAAC,OAAO,EAAE,EAAE;YACzC,MAAM,MAAM,GAAe,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,GAAG,EAAE,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC;QAC5F,CAAC,CAAC,CAAC;IACL,CAAC;;AAzDH,sDA0DC;AAED;;GAEG;AACH,MAAa,aAAc,SAAQ,qBAAqB;IACnC,gBAAgB;QAChC,IAAI,CAAC,IAAY,CAAC,EAAE,CAAC,MAAM,EAAE,CAAC,EAAO,EAAE,IAAS,EAAE,EAAE,CAAC,+BAAgB,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC,CAAC;QACpF,KAAK,CAAC,gBAAgB,EAAE,CAAC;IAC3B,CAAC;IAED,YAAY,QAA2B,EAAE,MAAM,GAAG,qBAAqB,CAAC,QAAQ;QAC9E,KAAK,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;QACxB,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACtB,CAAC;CACF;AAVD,sCAUC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\nimport * as express from \"express\";\nimport * as enableWs from \"express-ws\";\nimport { Server as HttpServer } from \"http\";\nimport { BentleyCloudRpcConfiguration, RpcConfiguration, WebAppRpcProtocol } from \"@itwin/core-common\";\nimport { LocalhostIpcHost } from \"@itwin/core-backend\";\n\n/**\n * Options for configuring IModelJsExpressServer.\n * @public\n */\nexport interface IModelJsExpressServerConfig {\n uploadLimit: string;\n}\n\n/**\n * An express web server with some reasonable defaults for web applications built with @bentley/webpack-tools.\n * @note This server is not designed to be a hardened, secure endpoint on the public internet.\n * It is intended to participate in a private HTTP exchange with a public-facing routing and provisioning infrastructure\n * that should be supplied by the application's deployment environment.\n * @public\n */\nexport class IModelJsExpressServer {\n /** The default configuration for servers. */\n public static readonly defaults: IModelJsExpressServerConfig = {\n uploadLimit: \"5mb\",\n };\n\n private _protocol: WebAppRpcProtocol;\n private _config: IModelJsExpressServerConfig;\n protected _app: import(\"express\").Application = express();\n\n /** @alpha */\n public get rpcConfiguration(): RpcConfiguration { return this._protocol.configuration; }\n\n constructor(protocol: WebAppRpcProtocol, config = IModelJsExpressServer.defaults) {\n this._protocol = protocol;\n this._config = config;\n }\n\n protected _configureMiddleware() {\n this._app.use(express.text({ limit: this._config.uploadLimit }));\n this._app.use(express.raw({ limit: this._config.uploadLimit }));\n }\n\n protected _configureHeaders() {\n // enable CORS for all apis\n this._app.all(\"/**\", (_req, res, next) => {\n res.header(\"Access-Control-Allow-Origin\", BentleyCloudRpcConfiguration.accessControl.allowOrigin);\n res.header(\"Access-Control-Allow-Methods\", BentleyCloudRpcConfiguration.accessControl.allowMethods);\n res.header(\"Access-Control-Allow-Headers\", BentleyCloudRpcConfiguration.accessControl.allowHeaders);\n next();\n });\n }\n\n protected _configureRoutes() {\n this._app.get(\"/v3/swagger.json\", (req, res) => this._protocol.handleOpenApiDescriptionRequest(req, res));\n this._app.post(\"*\", async (req, res) => this._protocol.handleOperationPostRequest(req, res));\n this._app.get(/\\/imodel\\//, async (req, res) => this._protocol.handleOperationGetRequest(req, res));\n this._app.get(\"/ping\", async (_req, res) => res.status(200).send(\"Success\"));\n // for all HTTP requests, identify the server.\n this._app.use(\"*\", (_req, resp) => {\n resp.send(\"<h1>IModelJs RPC Server</h1>\");\n });\n }\n\n /**\n * Configure the express application with necessary headers, routes, and middleware, then starts listening on the given port.\n * @param port The port to listen on\n */\n public async initialize(port: number | string): Promise<HttpServer> {\n this._configureMiddleware();\n this._configureHeaders();\n this._configureRoutes();\n\n this._app.set(\"port\", port);\n return new Promise<HttpServer>((resolve) => {\n const server: HttpServer = this._app.listen(this._app.get(\"port\"), () => resolve(server));\n });\n }\n}\n\n/**\n * @alpha\n */\nexport class WebEditServer extends IModelJsExpressServer {\n protected override _configureRoutes() {\n (this._app as any).ws(\"/ipc\", (ws: any, _req: any) => LocalhostIpcHost.connect(ws));\n super._configureRoutes();\n }\n\n constructor(protocol: WebAppRpcProtocol, config = IModelJsExpressServer.defaults) {\n super(protocol, config);\n enableWs(this._app);\n }\n}\n"]}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { Server as HttpServer } from "http";
|
|
2
|
+
import { RpcConfiguration, WebAppRpcProtocol } from "@itwin/core-common";
|
|
3
|
+
/**
|
|
4
|
+
* Options for configuring IModelJsExpressServer.
|
|
5
|
+
* @public
|
|
6
|
+
*/
|
|
7
|
+
export interface IModelJsExpressServerConfig {
|
|
8
|
+
uploadLimit: string;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* An express web server with some reasonable defaults for web applications built with @bentley/webpack-tools.
|
|
12
|
+
* @note This server is not designed to be a hardened, secure endpoint on the public internet.
|
|
13
|
+
* It is intended to participate in a private HTTP exchange with a public-facing routing and provisioning infrastructure
|
|
14
|
+
* that should be supplied by the application's deployment environment.
|
|
15
|
+
* @public
|
|
16
|
+
*/
|
|
17
|
+
export declare class IModelJsExpressServer {
|
|
18
|
+
/** The default configuration for servers. */
|
|
19
|
+
static readonly defaults: IModelJsExpressServerConfig;
|
|
20
|
+
private _protocol;
|
|
21
|
+
private _config;
|
|
22
|
+
protected _app: import("express").Application;
|
|
23
|
+
/** @alpha */
|
|
24
|
+
get rpcConfiguration(): RpcConfiguration;
|
|
25
|
+
constructor(protocol: WebAppRpcProtocol, config?: IModelJsExpressServerConfig);
|
|
26
|
+
protected _configureMiddleware(): void;
|
|
27
|
+
protected _configureHeaders(): void;
|
|
28
|
+
protected _configureRoutes(): void;
|
|
29
|
+
/**
|
|
30
|
+
* Configure the express application with necessary headers, routes, and middleware, then starts listening on the given port.
|
|
31
|
+
* @param port The port to listen on
|
|
32
|
+
*/
|
|
33
|
+
initialize(port: number | string): Promise<HttpServer>;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* @alpha
|
|
37
|
+
*/
|
|
38
|
+
export declare class WebEditServer extends IModelJsExpressServer {
|
|
39
|
+
protected _configureRoutes(): void;
|
|
40
|
+
constructor(protocol: WebAppRpcProtocol, config?: IModelJsExpressServerConfig);
|
|
41
|
+
}
|
|
42
|
+
//# sourceMappingURL=ExpressServer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ExpressServer.d.ts","sourceRoot":"","sources":["../../src/ExpressServer.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,MAAM,IAAI,UAAU,EAAE,MAAM,MAAM,CAAC;AAC5C,OAAO,EAAgC,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AAGvG;;;GAGG;AACH,MAAM,WAAW,2BAA2B;IAC1C,WAAW,EAAE,MAAM,CAAC;CACrB;AAED;;;;;;GAMG;AACH,qBAAa,qBAAqB;IAChC,6CAA6C;IAC7C,gBAAuB,QAAQ,EAAE,2BAA2B,CAE1D;IAEF,OAAO,CAAC,SAAS,CAAoB;IACrC,OAAO,CAAC,OAAO,CAA8B;IAC7C,SAAS,CAAC,IAAI,EAAE,OAAO,SAAS,EAAE,WAAW,CAAa;IAE1D,aAAa;IACb,IAAW,gBAAgB,IAAI,gBAAgB,CAAyC;gBAE5E,QAAQ,EAAE,iBAAiB,EAAE,MAAM,8BAAiC;IAKhF,SAAS,CAAC,oBAAoB;IAK9B,SAAS,CAAC,iBAAiB;IAU3B,SAAS,CAAC,gBAAgB;IAW1B;;;OAGG;IACU,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC;CAUpE;AAED;;GAEG;AACH,qBAAa,aAAc,SAAQ,qBAAqB;cACnC,gBAAgB;gBAKvB,QAAQ,EAAE,iBAAiB,EAAE,MAAM,8BAAiC;CAIjF"}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/*---------------------------------------------------------------------------------------------
|
|
2
|
+
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
|
|
3
|
+
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
4
|
+
*--------------------------------------------------------------------------------------------*/
|
|
5
|
+
import * as express from "express";
|
|
6
|
+
import * as enableWs from "express-ws";
|
|
7
|
+
import { BentleyCloudRpcConfiguration } from "@itwin/core-common";
|
|
8
|
+
import { LocalhostIpcHost } from "@itwin/core-backend";
|
|
9
|
+
/**
|
|
10
|
+
* An express web server with some reasonable defaults for web applications built with @bentley/webpack-tools.
|
|
11
|
+
* @note This server is not designed to be a hardened, secure endpoint on the public internet.
|
|
12
|
+
* It is intended to participate in a private HTTP exchange with a public-facing routing and provisioning infrastructure
|
|
13
|
+
* that should be supplied by the application's deployment environment.
|
|
14
|
+
* @public
|
|
15
|
+
*/
|
|
16
|
+
export class IModelJsExpressServer {
|
|
17
|
+
/** The default configuration for servers. */
|
|
18
|
+
static defaults = {
|
|
19
|
+
uploadLimit: "5mb",
|
|
20
|
+
};
|
|
21
|
+
_protocol;
|
|
22
|
+
_config;
|
|
23
|
+
_app = express();
|
|
24
|
+
/** @alpha */
|
|
25
|
+
get rpcConfiguration() { return this._protocol.configuration; }
|
|
26
|
+
constructor(protocol, config = IModelJsExpressServer.defaults) {
|
|
27
|
+
this._protocol = protocol;
|
|
28
|
+
this._config = config;
|
|
29
|
+
}
|
|
30
|
+
_configureMiddleware() {
|
|
31
|
+
this._app.use(express.text({ limit: this._config.uploadLimit }));
|
|
32
|
+
this._app.use(express.raw({ limit: this._config.uploadLimit }));
|
|
33
|
+
}
|
|
34
|
+
_configureHeaders() {
|
|
35
|
+
// enable CORS for all apis
|
|
36
|
+
this._app.all("/**", (_req, res, next) => {
|
|
37
|
+
res.header("Access-Control-Allow-Origin", BentleyCloudRpcConfiguration.accessControl.allowOrigin);
|
|
38
|
+
res.header("Access-Control-Allow-Methods", BentleyCloudRpcConfiguration.accessControl.allowMethods);
|
|
39
|
+
res.header("Access-Control-Allow-Headers", BentleyCloudRpcConfiguration.accessControl.allowHeaders);
|
|
40
|
+
next();
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
_configureRoutes() {
|
|
44
|
+
this._app.get("/v3/swagger.json", (req, res) => this._protocol.handleOpenApiDescriptionRequest(req, res));
|
|
45
|
+
this._app.post("*", async (req, res) => this._protocol.handleOperationPostRequest(req, res));
|
|
46
|
+
this._app.get(/\/imodel\//, async (req, res) => this._protocol.handleOperationGetRequest(req, res));
|
|
47
|
+
this._app.get("/ping", async (_req, res) => res.status(200).send("Success"));
|
|
48
|
+
// for all HTTP requests, identify the server.
|
|
49
|
+
this._app.use("*", (_req, resp) => {
|
|
50
|
+
resp.send("<h1>IModelJs RPC Server</h1>");
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Configure the express application with necessary headers, routes, and middleware, then starts listening on the given port.
|
|
55
|
+
* @param port The port to listen on
|
|
56
|
+
*/
|
|
57
|
+
async initialize(port) {
|
|
58
|
+
this._configureMiddleware();
|
|
59
|
+
this._configureHeaders();
|
|
60
|
+
this._configureRoutes();
|
|
61
|
+
this._app.set("port", port);
|
|
62
|
+
return new Promise((resolve) => {
|
|
63
|
+
const server = this._app.listen(this._app.get("port"), () => resolve(server));
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* @alpha
|
|
69
|
+
*/
|
|
70
|
+
export class WebEditServer extends IModelJsExpressServer {
|
|
71
|
+
_configureRoutes() {
|
|
72
|
+
this._app.ws("/ipc", (ws, _req) => LocalhostIpcHost.connect(ws));
|
|
73
|
+
super._configureRoutes();
|
|
74
|
+
}
|
|
75
|
+
constructor(protocol, config = IModelJsExpressServer.defaults) {
|
|
76
|
+
super(protocol, config);
|
|
77
|
+
enableWs(this._app);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
//# sourceMappingURL=ExpressServer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ExpressServer.js","sourceRoot":"","sources":["../../src/ExpressServer.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F,OAAO,KAAK,OAAO,MAAM,SAAS,CAAC;AACnC,OAAO,KAAK,QAAQ,MAAM,YAAY,CAAC;AAEvC,OAAO,EAAE,4BAA4B,EAAuC,MAAM,oBAAoB,CAAC;AACvG,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAUvD;;;;;;GAMG;AACH,MAAM,OAAO,qBAAqB;IAChC,6CAA6C;IACtC,MAAM,CAAU,QAAQ,GAAgC;QAC7D,WAAW,EAAE,KAAK;KACnB,CAAC;IAEM,SAAS,CAAoB;IAC7B,OAAO,CAA8B;IACnC,IAAI,GAAkC,OAAO,EAAE,CAAC;IAE1D,aAAa;IACb,IAAW,gBAAgB,KAAuB,OAAO,IAAI,CAAC,SAAS,CAAC,aAAa,CAAC,CAAC,CAAC;IAExF,YAAY,QAA2B,EAAE,MAAM,GAAG,qBAAqB,CAAC,QAAQ;QAC9E,IAAI,CAAC,SAAS,GAAG,QAAQ,CAAC;QAC1B,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;IACxB,CAAC;IAES,oBAAoB;QAC5B,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,IAAI,CAAC,OAAO,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC;QACjE,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,EAA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AC,SAAS,CAAC,CAAC,CAAC;QAC7E,8CAA8C;QAC9C,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,EAAE;YAChC,IAAI,CAAC,IAAI,CAAC,8BAA8B,CAAC,CAAC;QAC5C,CAAC,CAAC,CAAC;IACL,CAAC;IAED;;;OAGG;IACI,KAAK,CAAC,UAAU,CAAC,IAAqB;QAC3C,IAAI,CAAC,oBAAoB,EAAE,CAAC;QAC5B,IAAI,CAAC,iBAAiB,EAAE,CAAC;QACzB,IAAI,CAAC,gBAAgB,EAAE,CAAC;QAExB,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;QAC5B,OAAO,IAAI,OAAO,CAAa,CAAC,OAAO,EAAE,EAAE;YACzC,MAAM,MAAM,GAAe,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,GAAG,EAAE,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC;QAC5F,CAAC,CAAC,CAAC;IACL,CAAC;;AAGH;;GAEG;AACH,MAAM,OAAO,aAAc,SAAQ,qBAAqB;IACnC,gBAAgB;QAChC,IAAI,CAAC,IAAY,CAAC,EAAE,CAAC,MAAM,EAAE,CAAC,EAAO,EAAE,IAAS,EAAE,EAAE,CAAC,gBAAgB,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC,CAAC;QACpF,KAAK,CAAC,gBAAgB,EAAE,CAAC;IAC3B,CAAC;IAED,YAAY,QAA2B,EAAE,MAAM,GAAG,qBAAqB,CAAC,QAAQ;QAC9E,KAAK,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;QACxB,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACtB,CAAC;CACF","sourcesContent":["/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\nimport * as express from \"express\";\nimport * as enableWs from \"express-ws\";\nimport { Server as HttpServer } from \"http\";\nimport { BentleyCloudRpcConfiguration, RpcConfiguration, WebAppRpcProtocol } from \"@itwin/core-common\";\nimport { LocalhostIpcHost } from \"@itwin/core-backend\";\n\n/**\n * Options for configuring IModelJsExpressServer.\n * @public\n */\nexport interface IModelJsExpressServerConfig {\n uploadLimit: string;\n}\n\n/**\n * An express web server with some reasonable defaults for web applications built with @bentley/webpack-tools.\n * @note This server is not designed to be a hardened, secure endpoint on the public internet.\n * It is intended to participate in a private HTTP exchange with a public-facing routing and provisioning infrastructure\n * that should be supplied by the application's deployment environment.\n * @public\n */\nexport class IModelJsExpressServer {\n /** The default configuration for servers. */\n public static readonly defaults: IModelJsExpressServerConfig = {\n uploadLimit: \"5mb\",\n };\n\n private _protocol: WebAppRpcProtocol;\n private _config: IModelJsExpressServerConfig;\n protected _app: import(\"express\").Application = express();\n\n /** @alpha */\n public get rpcConfiguration(): RpcConfiguration { return this._protocol.configuration; }\n\n constructor(protocol: WebAppRpcProtocol, config = IModelJsExpressServer.defaults) {\n this._protocol = protocol;\n this._config = config;\n }\n\n protected _configureMiddleware() {\n this._app.use(express.text({ limit: this._config.uploadLimit }));\n this._app.use(express.raw({ limit: this._config.uploadLimit }));\n }\n\n protected _configureHeaders() {\n // enable CORS for all apis\n this._app.all(\"/**\", (_req, res, next) => {\n res.header(\"Access-Control-Allow-Origin\", BentleyCloudRpcConfiguration.accessControl.allowOrigin);\n res.header(\"Access-Control-Allow-Methods\", BentleyCloudRpcConfiguration.accessControl.allowMethods);\n res.header(\"Access-Control-Allow-Headers\", BentleyCloudRpcConfiguration.accessControl.allowHeaders);\n next();\n });\n }\n\n protected _configureRoutes() {\n this._app.get(\"/v3/swagger.json\", (req, res) => this._protocol.handleOpenApiDescriptionRequest(req, res));\n this._app.post(\"*\", async (req, res) => this._protocol.handleOperationPostRequest(req, res));\n this._app.get(/\\/imodel\\//, async (req, res) => this._protocol.handleOperationGetRequest(req, res));\n this._app.get(\"/ping\", async (_req, res) => res.status(200).send(\"Success\"));\n // for all HTTP requests, identify the server.\n this._app.use(\"*\", (_req, resp) => {\n resp.send(\"<h1>IModelJs RPC Server</h1>\");\n });\n }\n\n /**\n * Configure the express application with necessary headers, routes, and middleware, then starts listening on the given port.\n * @param port The port to listen on\n */\n public async initialize(port: number | string): Promise<HttpServer> {\n this._configureMiddleware();\n this._configureHeaders();\n this._configureRoutes();\n\n this._app.set(\"port\", port);\n return new Promise<HttpServer>((resolve) => {\n const server: HttpServer = this._app.listen(this._app.get(\"port\"), () => resolve(server));\n });\n }\n}\n\n/**\n * @alpha\n */\nexport class WebEditServer extends IModelJsExpressServer {\n protected override _configureRoutes() {\n (this._app as any).ws(\"/ipc\", (ws: any, _req: any) => LocalhostIpcHost.connect(ws));\n super._configureRoutes();\n }\n\n constructor(protocol: WebAppRpcProtocol, config = IModelJsExpressServer.defaults) {\n super(protocol, config);\n enableWs(this._app);\n }\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@itwin/express-server",
|
|
3
|
-
"version": "5.0.0-dev.
|
|
3
|
+
"version": "5.0.0-dev.92",
|
|
4
4
|
"description": "iTwin.js express utilities",
|
|
5
5
|
"main": "lib/cjs/ExpressServer.js",
|
|
6
|
+
"module": "lib/esm/ExpressServer.js",
|
|
6
7
|
"typings": "lib/cjs/ExpressServer",
|
|
7
8
|
"license": "MIT",
|
|
8
9
|
"engines": {
|
|
@@ -30,37 +31,38 @@
|
|
|
30
31
|
"@types/chai": "4.3.1",
|
|
31
32
|
"@types/express": "^4.17.20",
|
|
32
33
|
"@types/mocha": "^10.0.6",
|
|
33
|
-
"@types/node": "~20.
|
|
34
|
+
"@types/node": "~20.17.0",
|
|
34
35
|
"@types/sinon": "^17.0.2",
|
|
35
36
|
"@types/supertest": "^6.0.2",
|
|
36
37
|
"@types/express-ws": "^3.0.3",
|
|
37
38
|
"chai": "^4.3.10",
|
|
38
39
|
"eslint": "^9.13.0",
|
|
39
|
-
"mocha": "^
|
|
40
|
-
"nyc": "^
|
|
41
|
-
"rimraf": "^
|
|
40
|
+
"mocha": "^11.1.0",
|
|
41
|
+
"nyc": "^17.1.0",
|
|
42
|
+
"rimraf": "^6.0.1",
|
|
42
43
|
"sinon": "^17.0.2",
|
|
43
44
|
"supertest": "^7.0.0",
|
|
44
45
|
"typescript": "~5.6.2",
|
|
45
|
-
"@itwin/build-tools": "5.0.0-dev.
|
|
46
|
-
"@itwin/core-
|
|
47
|
-
"@itwin/core-
|
|
46
|
+
"@itwin/build-tools": "5.0.0-dev.92",
|
|
47
|
+
"@itwin/core-common": "5.0.0-dev.92",
|
|
48
|
+
"@itwin/core-backend": "5.0.0-dev.92"
|
|
48
49
|
},
|
|
49
50
|
"peerDependencies": {
|
|
50
|
-
"@itwin/core-backend": "5.0.0-dev.
|
|
51
|
-
"@itwin/core-common": "5.0.0-dev.
|
|
51
|
+
"@itwin/core-backend": "5.0.0-dev.92",
|
|
52
|
+
"@itwin/core-common": "5.0.0-dev.92"
|
|
52
53
|
},
|
|
53
54
|
"dependencies": {
|
|
54
|
-
"express": "^4.
|
|
55
|
+
"express": "^4.21.2",
|
|
55
56
|
"express-ws": "^5.0.2"
|
|
56
57
|
},
|
|
57
58
|
"nyc": {
|
|
58
59
|
"extends": "./node_modules/@itwin/build-tools/.nycrc"
|
|
59
60
|
},
|
|
60
61
|
"scripts": {
|
|
61
|
-
"build": "npm run -s build:cjs",
|
|
62
|
+
"build": "npm run -s build:cjs && npm run -s build:esm",
|
|
62
63
|
"build:cjs": "tsc 1>&2 --outDir lib/cjs",
|
|
63
|
-
"
|
|
64
|
+
"build:esm": "tsc 1>&2 --module ES2022 --outDir lib/esm",
|
|
65
|
+
"clean": "rimraf -g lib .rush/temp/package-deps*.json",
|
|
64
66
|
"docs": "betools docs --json=../../generated-docs/core/express-server/file.json --tsIndexFile=./ExpressServer.ts --onlyJson",
|
|
65
67
|
"extract-api": "betools extract-api --entry=ExpressServer",
|
|
66
68
|
"lint": "eslint \"./src/**/*.ts\" 1>&2",
|