const express = require('express'); const router = express.Router(); const settingsController = require('../controllers/settingsController'); const dashboardRoutes = require('./dashboard'); const dataConvertRoutes = require('./dataConvert'); // Debug endpoint to check configuration router.get('/config-debug', (req, res) => { const config = require('../config'); res.json({ success: true, config: { nocodb: { apiUrl: config.nocodb.apiUrl, hasToken: !!config.nocodb.apiToken, projectId: config.nocodb.projectId, tableId: config.nocodb.tableId, loginSheetId: config.nocodb.loginSheetId, settingsSheetId: config.nocodb.settingsSheetId, shiftsSheetId: config.nocodb.shiftsSheetId, shiftSignupsSheetId: config.nocodb.shiftSignupsSheetId } } }); }); // Start location management router.get('/start-location', settingsController.getStartLocation); router.post('/start-location', settingsController.updateStartLocation); // Walk sheet configuration router.get('/walk-sheet-config', settingsController.getWalkSheetConfig); router.post('/walk-sheet-config', settingsController.updateWalkSheetConfig); // Dashboard routes router.use('/dashboard', dashboardRoutes); // Data convert routes router.use('/data-convert', dataConvertRoutes); // Get NocoDB URLs for admin panel router.get('/nocodb-urls', (req, res) => { console.log('Admin NocoDB URLs endpoint called'); // Return the NocoDB URLs directly from environment variables // Since this route is protected by requireAdmin middleware, // we know the user is an admin const nocodbUrls = { viewUrl: process.env.NOCODB_VIEW_URL, loginSheet: process.env.NOCODB_LOGIN_SHEET, settingsSheet: process.env.NOCODB_SETTINGS_SHEET, shiftsSheet: process.env.NOCODB_SHIFTS_SHEET, shiftSignupsSheet: process.env.NOCODB_SHIFT_SIGNUPS_SHEET }; console.log('Returning NocoDB URLs for admin:', { hasViewUrl: !!nocodbUrls.viewUrl, hasLoginSheet: !!nocodbUrls.loginSheet, hasSettingsSheet: !!nocodbUrls.settingsSheet, hasShiftsSheet: !!nocodbUrls.shiftsSheet, hasSignupsSheet: !!nocodbUrls.shiftSignupsSheet }); res.json({ success: true, nocodbUrls }); }); // Get Listmonk URLs for admin panel router.get('/listmonk-urls', (req, res) => { console.log('Admin Listmonk URLs endpoint called'); // Construct Listmonk URLs using the public domain // Since this route is protected by requireAdmin middleware, // we know the user is an admin const domain = process.env.DOMAIN; let listmonkBaseUrl = null; if (domain) { // Construct the public Listmonk URL using the domain // Format: https://listmonk.{domain} listmonkBaseUrl = `https://listmonk.${domain}`; } const listmonkUrls = { baseUrl: listmonkBaseUrl, adminUrl: listmonkBaseUrl ? `${listmonkBaseUrl}/admin` : null, listsUrl: listmonkBaseUrl ? `${listmonkBaseUrl}/admin/lists` : null, campaignsUrl: listmonkBaseUrl ? `${listmonkBaseUrl}/admin/campaigns` : null, subscribersUrl: listmonkBaseUrl ? `${listmonkBaseUrl}/admin/subscribers` : null, settingsUrl: listmonkBaseUrl ? `${listmonkBaseUrl}/admin/settings` : null }; console.log('Returning Listmonk URLs for admin:', { domain: domain, baseUrl: listmonkBaseUrl, hasAdminUrl: !!listmonkUrls.adminUrl, hasListsUrl: !!listmonkUrls.listsUrl, hasCampaignsUrl: !!listmonkUrls.campaignsUrl, hasSubscribersUrl: !!listmonkUrls.subscribersUrl, hasSettingsUrl: !!listmonkUrls.settingsUrl }); res.json({ success: true, listmonkUrls }); }); module.exports = router;