@friggframework/core 2.0.0--canary.424.a864ff6.0 → 2.0.0--canary.419.daed467.0
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/database/mongo.js +82 -0
- package/package.json +5 -5
package/database/mongo.js
CHANGED
|
@@ -5,10 +5,29 @@
|
|
|
5
5
|
const { Encrypt } = require('../encrypt');
|
|
6
6
|
const { mongoose } = require('./mongoose');
|
|
7
7
|
const { debug, flushDebugLog } = require('../logs');
|
|
8
|
+
const { findNearestBackendPackageJson } = require('../utils');
|
|
9
|
+
const path = require('path');
|
|
10
|
+
const fs = require('fs');
|
|
8
11
|
|
|
9
12
|
mongoose.plugin(Encrypt);
|
|
10
13
|
mongoose.set('applyPluginsToDiscriminators', true); // Needed for LHEncrypt
|
|
11
14
|
|
|
15
|
+
// Load app definition to check for DocumentDB configuration
|
|
16
|
+
let appDefinition = {};
|
|
17
|
+
try {
|
|
18
|
+
const backendPath = findNearestBackendPackageJson();
|
|
19
|
+
if (backendPath) {
|
|
20
|
+
const backendDir = path.dirname(backendPath);
|
|
21
|
+
const backendFilePath = path.join(backendDir, 'index.js');
|
|
22
|
+
if (fs.existsSync(backendFilePath)) {
|
|
23
|
+
const backendJsFile = require(backendFilePath);
|
|
24
|
+
appDefinition = backendJsFile.Definition || {};
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
} catch (error) {
|
|
28
|
+
debug('Could not load app definition for DocumentDB configuration:', error.message);
|
|
29
|
+
}
|
|
30
|
+
|
|
12
31
|
// Buffering means mongoose will queue up operations if it gets
|
|
13
32
|
// With serverless, better to fail fast if not connected.
|
|
14
33
|
// disconnected from MongoDB and send them when it reconnects.
|
|
@@ -20,6 +39,65 @@ const mongoConfig = {
|
|
|
20
39
|
serverSelectionTimeoutMS: 5000,
|
|
21
40
|
};
|
|
22
41
|
|
|
42
|
+
// Add DocumentDB TLS configuration if enabled
|
|
43
|
+
if (appDefinition.database?.documentDB?.enable === true) {
|
|
44
|
+
console.log('📄 DocumentDB configuration detected, enabling TLS');
|
|
45
|
+
console.log('📁 Current working directory:', process.cwd());
|
|
46
|
+
console.log('📋 App definition database config:', JSON.stringify(appDefinition.database, null, 2));
|
|
47
|
+
|
|
48
|
+
mongoConfig.tls = true;
|
|
49
|
+
|
|
50
|
+
// Set TLS CA file path if specified
|
|
51
|
+
if (appDefinition.database.documentDB.tlsCAFile) {
|
|
52
|
+
const tlsCAFile = appDefinition.database.documentDB.tlsCAFile;
|
|
53
|
+
|
|
54
|
+
// Basic safety: reject obviously dangerous paths
|
|
55
|
+
if (tlsCAFile.includes('..') || path.isAbsolute(tlsCAFile)) {
|
|
56
|
+
console.warn('⚠️ Rejecting potentially unsafe tlsCAFile path:', tlsCAFile);
|
|
57
|
+
} else {
|
|
58
|
+
const tlsCAFilePath = path.resolve(process.cwd(), tlsCAFile);
|
|
59
|
+
|
|
60
|
+
console.log('📄 DocumentDB TLS CA file configured:');
|
|
61
|
+
console.log(' 📎 Original path:', tlsCAFile);
|
|
62
|
+
console.log(' 📎 Resolved path:', tlsCAFilePath);
|
|
63
|
+
console.log(' 📄 File exists:', fs.existsSync(tlsCAFilePath));
|
|
64
|
+
|
|
65
|
+
// Only set tlsCAFile if the file actually exists
|
|
66
|
+
if (fs.existsSync(tlsCAFilePath)) {
|
|
67
|
+
mongoConfig.tlsCAFile = tlsCAFilePath;
|
|
68
|
+
console.log('✅ TLS CA file configured successfully');
|
|
69
|
+
} else {
|
|
70
|
+
console.error('❌ TLS CA file not found, continuing without certificate');
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// Debug directory listing (only in development)
|
|
74
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
75
|
+
try {
|
|
76
|
+
console.log('📁 Current directory contents:');
|
|
77
|
+
fs.readdirSync(process.cwd()).forEach(item => {
|
|
78
|
+
const stats = fs.statSync(path.join(process.cwd(), item));
|
|
79
|
+
console.log(` ${stats.isDirectory() ? '📁' : '📄'} ${item}`);
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
const securityDir = path.join(process.cwd(), 'security');
|
|
83
|
+
if (fs.existsSync(securityDir)) {
|
|
84
|
+
console.log('📁 Security directory contents:');
|
|
85
|
+
fs.readdirSync(securityDir).forEach(item => {
|
|
86
|
+
console.log(` 📄 ${item}`);
|
|
87
|
+
});
|
|
88
|
+
} else {
|
|
89
|
+
console.log('❌ Security directory does not exist at:', securityDir);
|
|
90
|
+
}
|
|
91
|
+
} catch (error) {
|
|
92
|
+
console.log('❌ Error listing directory contents:', error.message);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
} else {
|
|
98
|
+
console.log('📄 DocumentDB not enabled, using standard MongoDB configuration');
|
|
99
|
+
}
|
|
100
|
+
|
|
23
101
|
const checkIsConnected = () => mongoose.connection?.readyState > 0;
|
|
24
102
|
|
|
25
103
|
const connectToDatabase = async () => {
|
|
@@ -28,6 +106,10 @@ const connectToDatabase = async () => {
|
|
|
28
106
|
return;
|
|
29
107
|
}
|
|
30
108
|
|
|
109
|
+
console.log('🔗 Connecting to database...');
|
|
110
|
+
console.log('🔗 MongoDB URI:', process.env.MONGO_URI ? 'SET' : 'NOT SET');
|
|
111
|
+
console.log('🔧 Final mongoConfig:', JSON.stringify(mongoConfig, null, 2));
|
|
112
|
+
|
|
31
113
|
debug('=> using new database connection');
|
|
32
114
|
await mongoose.connect(process.env.MONGO_URI, mongoConfig);
|
|
33
115
|
debug('Connection state:', mongoose.STATES[mongoose.connection.readyState]);
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@friggframework/core",
|
|
3
3
|
"prettier": "@friggframework/prettier-config",
|
|
4
|
-
"version": "2.0.0--canary.
|
|
4
|
+
"version": "2.0.0--canary.419.daed467.0",
|
|
5
5
|
"dependencies": {
|
|
6
6
|
"@hapi/boom": "^10.0.1",
|
|
7
7
|
"aws-sdk": "^2.1200.0",
|
|
@@ -22,9 +22,9 @@
|
|
|
22
22
|
"uuid": "^9.0.1"
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
25
|
-
"@friggframework/eslint-config": "2.0.0--canary.
|
|
26
|
-
"@friggframework/prettier-config": "2.0.0--canary.
|
|
27
|
-
"@friggframework/test": "2.0.0--canary.
|
|
25
|
+
"@friggframework/eslint-config": "2.0.0--canary.419.daed467.0",
|
|
26
|
+
"@friggframework/prettier-config": "2.0.0--canary.419.daed467.0",
|
|
27
|
+
"@friggframework/test": "2.0.0--canary.419.daed467.0",
|
|
28
28
|
"@types/lodash": "4.17.15",
|
|
29
29
|
"@typescript-eslint/eslint-plugin": "^8.0.0",
|
|
30
30
|
"chai": "^4.3.6",
|
|
@@ -56,5 +56,5 @@
|
|
|
56
56
|
"publishConfig": {
|
|
57
57
|
"access": "public"
|
|
58
58
|
},
|
|
59
|
-
"gitHead": "
|
|
59
|
+
"gitHead": "daed467862dc5acc37b4dd9e48ea62444da598be"
|
|
60
60
|
}
|