generated from pagopa/io-functions-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.ts
53 lines (41 loc) · 1.67 KB
/
index.ts
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
import * as express from "express";
import * as winston from "winston";
import { Context } from "@azure/functions";
import {
SERVICE_COLLECTION_NAME,
ServiceModel
} from "@pagopa/io-functions-commons/dist/src/models/service";
import { secureExpressApp } from "@pagopa/io-functions-commons/dist/src/utils/express";
import { AzureContextTransport } from "@pagopa/io-functions-commons/dist/src/utils/logging";
import { setAppContext } from "@pagopa/io-functions-commons/dist/src/utils/middlewares/context_middleware";
import createAzureFunctionHandler from "@pagopa/express-azure-functions/dist/src/createAzureFunctionsHandler";
import { getConfigOrThrow } from "../utils/config";
import { cosmosdbClient } from "../utils/cosmosdb";
import { HttpCtrl } from "./handler";
//
// CosmosDB initialization
//
const config = getConfigOrThrow();
const servicesContainer = cosmosdbClient
.database(config.COSMOSDB_NAME)
.container(SERVICE_COLLECTION_NAME);
const serviceModel = new ServiceModel(servicesContainer);
// eslint-disable-next-line functional/no-let
let logger: Context["log"] | undefined;
const contextTransport = new AzureContextTransport(() => logger, {
level: "debug"
});
winston.add(contextTransport);
// Setup Express
const app = express();
secureExpressApp(app);
// Add express route
app.get("/some/path/:someParam", HttpCtrl(serviceModel));
const azureFunctionHandler = createAzureFunctionHandler(app);
// Binds the express app to an Azure Function handler
const httpStart = (context: Context): void => {
logger = context.log;
setAppContext(app, context);
azureFunctionHandler(context);
};
export default httpStart;