parse-dashboard-analytics 1.0.7 → 1.0.9

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.
@@ -1093,9 +1093,12 @@ You have direct access to the Parse database through function calls, so you can
1093
1093
  `);
1094
1094
  });
1095
1095
 
1096
- // Analytics dashboard route
1096
+ // Analytics dashboard routes - Only serve custom analytics if analyticsPage is configured
1097
1097
  app.get('/apps/*/analytics_dashboard', function(req, res) {
1098
+ console.log('🎯 Analytics dashboard route hit:', req.path, req.url);
1099
+
1098
1100
  if (users && (!req.user || !req.user.isAuthenticated)) {
1101
+ console.log('🔒 User not authenticated, redirecting to login');
1099
1102
  const redirect = req.url.replace('/login', '');
1100
1103
  if (redirect.length > 1) {
1101
1104
  return res.redirect(`${mountPath}login?redirect=${redirect}`);
@@ -1106,29 +1109,100 @@ You have direct access to the Parse database through function calls, so you can
1106
1109
  // Extract app ID from URL
1107
1110
  const appIdMatch = req.path.match(/\/apps\/([^\/]+)\/analytics_dashboard/);
1108
1111
  const appId = appIdMatch ? appIdMatch[1] : null;
1112
+ console.log('📱 Extracted app ID:', appId);
1109
1113
 
1110
1114
  // Find the app configuration
1111
1115
  let customAnalyticsPath = null;
1112
1116
  if (appId && config.apps) {
1113
- const app = config.apps.find(app => app.appId === appId || app.appName === appId);
1117
+ const app = config.apps.find(app => app.appId === appId || app.appNameForURL === appId || app.appName === appId);
1118
+ console.log('🔍 Found app config:', app ? 'YES' : 'NO', app ? app.analyticsPage : 'N/A');
1114
1119
  if (app && app.analyticsPage) {
1115
1120
  customAnalyticsPath = app.analyticsPage;
1116
1121
  }
1117
1122
  }
1118
1123
 
1119
- // Use custom analytics page if specified, otherwise use default
1120
- const analyticsFile = customAnalyticsPath || path.join(__dirname, 'public', 'analytics.html');
1124
+ // Only serve custom analytics page if analyticsPage is configured
1125
+ if (customAnalyticsPath) {
1126
+ console.log('✅ Using custom analytics path:', customAnalyticsPath);
1127
+ if (customAnalyticsPath.startsWith('/')) {
1128
+ // It's a URL path, serve from public directory
1129
+ const publicPath = path.join(__dirname, 'public', customAnalyticsPath);
1130
+ console.log('📁 Serving from public directory:', publicPath);
1131
+ if (fs.existsSync(publicPath)) {
1132
+ return res.sendFile(publicPath);
1133
+ } else {
1134
+ console.warn(`Custom analytics page not found in public directory: ${publicPath}, falling back to React component`);
1135
+ }
1136
+ } else {
1137
+ // It's an absolute file path
1138
+ console.log('📁 Serving from absolute path:', customAnalyticsPath);
1139
+ if (fs.existsSync(customAnalyticsPath)) {
1140
+ return res.sendFile(path.resolve(customAnalyticsPath));
1141
+ } else {
1142
+ console.warn(`Custom analytics page not found: ${customAnalyticsPath}, falling back to React component`);
1143
+ }
1144
+ }
1145
+ }
1146
+
1147
+ // No custom analytics page configured or file not found - let React component handle it
1148
+ console.log('🔄 No custom analyticsPage configured, falling through to React component');
1149
+ return; // This will fall through to the catch-all route for React routing
1150
+ });
1151
+
1152
+ // Alternative analytics dashboard route (with slash instead of underscore)
1153
+ app.get('/apps/*/analytics/dashboard', function(req, res) {
1154
+ console.log('🎯 Alternative analytics route hit:', req.path, req.url);
1155
+
1156
+ if (users && (!req.user || !req.user.isAuthenticated)) {
1157
+ console.log('🔒 User not authenticated, redirecting to login');
1158
+ const redirect = req.url.replace('/login', '');
1159
+ if (redirect.length > 1) {
1160
+ return res.redirect(`${mountPath}login?redirect=${redirect}`);
1161
+ }
1162
+ return res.redirect(`${mountPath}login`);
1163
+ }
1164
+
1165
+ // Extract app ID from URL
1166
+ const appIdMatch = req.path.match(/\/apps\/([^\/]+)\/analytics\/dashboard/);
1167
+ const appId = appIdMatch ? appIdMatch[1] : null;
1168
+ console.log('📱 Extracted app ID:', appId);
1169
+
1170
+ // Find the app configuration
1171
+ let customAnalyticsPath = null;
1172
+ if (appId && config.apps) {
1173
+ const app = config.apps.find(app => app.appId === appId || app.appNameForURL === appId || app.appName === appId);
1174
+ console.log('🔍 Found app config:', app ? 'YES' : 'NO', app ? app.analyticsPage : 'N/A');
1175
+ if (app && app.analyticsPage) {
1176
+ customAnalyticsPath = app.analyticsPage;
1177
+ }
1178
+ }
1121
1179
 
1122
- // Check if custom file exists
1180
+ // Only serve custom analytics page if analyticsPage is configured
1123
1181
  if (customAnalyticsPath) {
1124
- const fs = require('fs');
1125
- if (!fs.existsSync(customAnalyticsPath)) {
1126
- console.warn(`Custom analytics page not found: ${customAnalyticsPath}, falling back to default`);
1127
- return res.sendFile(path.join(__dirname, 'public', 'analytics.html'));
1182
+ console.log('✅ Using custom analytics path:', customAnalyticsPath);
1183
+ if (customAnalyticsPath.startsWith('/')) {
1184
+ // It's a URL path, serve from public directory
1185
+ const publicPath = path.join(__dirname, 'public', customAnalyticsPath);
1186
+ console.log('📁 Serving from public directory:', publicPath);
1187
+ if (fs.existsSync(publicPath)) {
1188
+ return res.sendFile(publicPath);
1189
+ } else {
1190
+ console.warn(`Custom analytics page not found in public directory: ${publicPath}, falling back to React component`);
1191
+ }
1192
+ } else {
1193
+ // It's an absolute file path
1194
+ console.log('📁 Serving from absolute path:', customAnalyticsPath);
1195
+ if (fs.existsSync(customAnalyticsPath)) {
1196
+ return res.sendFile(path.resolve(customAnalyticsPath));
1197
+ } else {
1198
+ console.warn(`Custom analytics page not found: ${customAnalyticsPath}, falling back to React component`);
1199
+ }
1128
1200
  }
1129
1201
  }
1130
1202
 
1131
- res.sendFile(path.resolve(analyticsFile));
1203
+ // No custom analytics page configured or file not found - let React component handle it
1204
+ console.log('🔄 No custom analyticsPage configured, falling through to React component');
1205
+ return; // This will fall through to the catch-all route for React routing
1132
1206
  });
1133
1207
 
1134
1208
  // For every other request, go to index.html. Let client-side handle the rest.
@@ -1,15 +1,17 @@
1
1
  {
2
2
  "apps": [
3
3
  {
4
- "serverURL": "http://localhost:1338/parse",
5
- "appId": "mock-app-id",
6
- "masterKey": "mock-master-key",
4
+ "serverURL": "http://localhost:1339/parse",
5
+ "appId": "analytics-demo-app",
6
+ "masterKey": "your-master-key-here",
7
7
  "appName": "Parse Dashboard Analytics Demo",
8
- "appNameForURL": "mock-app-id",
8
+ "appNameForURL": "analytics-demo-app",
9
9
  "iconName": "",
10
10
  "primaryBackgroundColor": "#169CEE",
11
11
  "secondaryBackgroundColor": "#0F5B8A",
12
- "analyticsPage": "/Users/prayercircle/Development/parse-dashboard/parse-dashboard-analytics-dist/simple-analytics.html"
12
+ "analytics": {
13
+ "endpoint": "http://localhost:1339"
14
+ }
13
15
  }
14
16
  ],
15
17
  "users": [
@@ -150,21 +150,22 @@
150
150
  </a>
151
151
 
152
152
  <div class="analytics-header">
153
- <h1>Analytics Dashboard</h1>
154
- <p>Real-time insights and metrics for your Parse application</p>
153
+ <h1>🔧 MODIFIED Analytics Dashboard - TEST VERSION</h1>
154
+ <p>⚠️ This is the DEFAULT analytics.html file - NOT the custom one!</p>
155
+ <p style="color: red; font-weight: bold;">If you see this, the custom analyticsPage config is not working properly.</p>
155
156
  </div>
156
157
 
157
158
  <div class="metrics-grid">
158
159
  <div class="metric-card">
159
- <div class="metric-value">1,247</div>
160
- <div class="metric-label">Total Users</div>
161
- <div class="metric-change positive">+12% from last month</div>
160
+ <div class="metric-value">🚨 WRONG FILE 🚨</div>
161
+ <div class="metric-label">This is analytics.html</div>
162
+ <div class="metric-change negative">Should be simple-analytics.html</div>
162
163
  </div>
163
164
 
164
165
  <div class="metric-card">
165
- <div class="metric-value">3,891</div>
166
- <div class="metric-label">Total Objects</div>
167
- <div class="metric-change positive">+8% from last month</div>
166
+ <div class="metric-value">❌ CONFIG ISSUE</div>
167
+ <div class="metric-label">analyticsPage not working</div>
168
+ <div class="metric-change negative">Check configuration</div>
168
169
  </div>
169
170
 
170
171
  <div class="metric-card">