-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.ts
More file actions
49 lines (45 loc) · 2.39 KB
/
main.ts
File metadata and controls
49 lines (45 loc) · 2.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/*---------------------------------------------------------------------------------------------
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
* See LICENSE.md in the project root for license terms and full copyright notice.
*--------------------------------------------------------------------------------------------*/
import { IModelHost } from "@itwin/core-backend";
import { Logger, LogLevel } from "@itwin/core-bentley";
import { BentleyCloudRpcManager, IModelReadRpcInterface, IModelTileRpcInterface, RpcManager } from "@itwin/core-common";
import { ECSchemaRpcInterface } from "@itwin/ecschema-rpcinterface-common";
import { ECSchemaRpcImpl } from "@itwin/ecschema-rpcinterface-impl";
import { IModelJsExpressServer } from "@itwin/express-server";
import { BackendIModelsAccess } from "@itwin/imodels-access-backend";
import { IModelsClientOptions } from "@itwin/imodels-client-authoring";
import { AzureClientStorage, BlockBlobClientWrapperFactory } from "@itwin/object-storage-azure";
import { Presentation } from "@itwin/presentation-backend";
import { PresentationRpcInterface } from "@itwin/presentation-common";
import { config } from "dotenv-flow";
import { ChangesRpcImpl } from "./RPC/ChangesRpcImpl";
import { ChangesRpcInterface } from "./RPC/ChangesRpcInterface";
config({ path: "../test-app-frontend" });
const port = Number.parseInt(process.env.VITE_LOCAL_BACKEND_PORT ?? "", 10);
void (async () => {
Logger.initializeToConsole();
Logger.setLevelDefault(LogLevel.Info);
const opts: IModelsClientOptions = {
cloudStorage: new AzureClientStorage(new BlockBlobClientWrapperFactory()),
api: {
baseUrl: `https://${process.env.VITE_URL_PREFIX}api.bentley.com/imodels`,
version: "itwin-platform.v2",
},
};
await IModelHost.startup({
cacheDir: `./.cache_${port}`,
hubAccess: new BackendIModelsAccess(opts),
});
Presentation.initialize();
ECSchemaRpcImpl.register();
RpcManager.registerImpl(ChangesRpcInterface, ChangesRpcImpl);
const rpcConfig = BentleyCloudRpcManager.initializeImpl(
{ info: { title: "test-app-backend", version: "v1.0" } },
[IModelReadRpcInterface, IModelTileRpcInterface, PresentationRpcInterface, ChangesRpcInterface, ECSchemaRpcInterface],
);
const server = new IModelJsExpressServer(rpcConfig.protocol);
await server.initialize(port);
console.log(`Backend (PID ${process.pid}) is listening on port ${port}.`);
})();