-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathserver.js
More file actions
54 lines (43 loc) · 1.75 KB
/
server.js
File metadata and controls
54 lines (43 loc) · 1.75 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
50
51
52
53
54
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
const config = require("./config");
const express = require("express");
const { targetingContextAccessor, requestStorageMiddleware } = require("./targetingContextAccessor");
const { initializeAppInsights } = require("./telemetry");
const { initializeFeatureManagement, featureFlagRefreshMiddleware } = require("./featureManagement");
const { initializeRoutes } = require("./routes");
// Initialize Express server
const server = express();
// Initialize Application Insights
const appInsights = initializeAppInsights(targetingContextAccessor);
// Global variables to store feature manager and app config
let featureManager;
// Initialize the configuration and start the server
async function startApp() {
try {
// Initialize AppConfig and FeatureManager
const result = await initializeFeatureManagement(
appInsights.defaultClient,
targetingContextAccessor
);
featureManager = result.featureManager;
console.log("Configuration loaded. Starting server...");
// Set up middleware
server.use(requestStorageMiddleware);
server.use(featureFlagRefreshMiddleware);
server.use(express.json());
server.use(express.static("public"));
// Set up routes
const routes = initializeRoutes(featureManager, appInsights.defaultClient);
server.use(routes);
// Start the server
server.listen(config.port, () => {
console.log(`Server is running at http://localhost:${config.port}`);
});
} catch (error) {
console.error("Failed to load configuration:", error);
process.exit(1);
}
}
// Start the application
startApp();