Deploy to production - ensure all endpoints operational
This commit is contained in:
64
api/deploy-package/DIContainer.js
Normal file
64
api/deploy-package/DIContainer.js
Normal file
@@ -0,0 +1,64 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const cosmos_1 = require("@azure/cosmos");
|
||||
const keyvault_secrets_1 = require("@azure/keyvault-secrets");
|
||||
const identity_1 = require("@azure/identity");
|
||||
class DIContainer {
|
||||
static instance;
|
||||
services = null;
|
||||
constructor() { }
|
||||
static getInstance() {
|
||||
if (!DIContainer.instance) {
|
||||
DIContainer.instance = new DIContainer();
|
||||
}
|
||||
return DIContainer.instance;
|
||||
}
|
||||
async initializeServices() {
|
||||
if (this.services) {
|
||||
return this.services;
|
||||
}
|
||||
try {
|
||||
// Initialize Cosmos DB
|
||||
const cosmosConnectionString = process.env.COSMOS_CONNECTION_STRING;
|
||||
if (!cosmosConnectionString) {
|
||||
throw new Error('COSMOS_CONNECTION_STRING is not configured');
|
||||
}
|
||||
const cosmosClient = new cosmos_1.CosmosClient(cosmosConnectionString);
|
||||
const databaseName = process.env.COSMOS_DATABASE_NAME || 'MiraclesInMotion';
|
||||
const database = cosmosClient.database(databaseName);
|
||||
// Get containers
|
||||
const donationsContainer = database.container('donations');
|
||||
const volunteersContainer = database.container('volunteers');
|
||||
const programsContainer = database.container('programs');
|
||||
// Initialize Key Vault
|
||||
const keyVaultUrl = process.env.KEY_VAULT_URL;
|
||||
if (!keyVaultUrl) {
|
||||
throw new Error('KEY_VAULT_URL is not configured');
|
||||
}
|
||||
const credential = new identity_1.DefaultAzureCredential();
|
||||
const secretClient = new keyvault_secrets_1.SecretClient(keyVaultUrl, credential);
|
||||
this.services = {
|
||||
cosmosClient,
|
||||
database,
|
||||
donationsContainer,
|
||||
volunteersContainer,
|
||||
programsContainer,
|
||||
secretClient
|
||||
};
|
||||
console.log('✅ Services initialized successfully');
|
||||
return this.services;
|
||||
}
|
||||
catch (error) {
|
||||
console.error('❌ Failed to initialize services:', error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
getServices() {
|
||||
if (!this.services) {
|
||||
throw new Error('Services not initialized. Call initializeServices() first.');
|
||||
}
|
||||
return this.services;
|
||||
}
|
||||
}
|
||||
exports.default = DIContainer;
|
||||
//# sourceMappingURL=DIContainer.js.map
|
||||
Reference in New Issue
Block a user