feat: complete implementation of dynamic GlobeMap coordinates, TDD workflow, and UI/UX enhancements

This commit is contained in:
Rafif-Riqullah-Siregar committed 2026-07-07 23:25:59 +07:00
1 parent 8ba1d8f959
commit 764c87c3c8
75 files changed
+3666 -1153

No files matched your search

+19 -14
View File
@@ -1,15 +1,23 @@
// backend/server.js
// backend/server.js
const path = require('path');
require('dotenv').config({ path: path.join(__dirname, '..', '.env.local') });
const express = require('express');
const cors = require('cors');
const cookieParser = require('cookie-parser');
const jwt = require('jsonwebtoken');
const connectDB = require('./db/mongoose');
// Connect to MongoDB
connectDB();
// Start Data Ingestion Scheduler
const { startScheduler } = require('./services/ingestionService');
startScheduler();
const app = express();
const PORT = process.env.BACKEND_PORT || 3001;
// ── Middleware ────────────────────────────────────────────────────────────────
// ── Middleware ────────────────────────────────────────────────────────────────
const ALLOWED_ORIGINS = process.env.ALLOWED_ORIGINS
? process.env.ALLOWED_ORIGINS.split(',')
: ['http://localhost:3000', 'http://127.0.0.1:3000'];
@@ -28,7 +36,7 @@ app.use(cors({
app.use(express.json());
app.use(cookieParser());
// ── API Routes ────────────────────────────────────────────────────────────────
// ── API Routes ────────────────────────────────────────────────────────────────
const authRoutes = require('./routes/auth');
app.use('/api/auth', authRoutes);
app.use('/api/uploads', express.static(path.join(__dirname, 'uploads')));
@@ -41,7 +49,7 @@ function requireAuth(req, res, next) {
try {
req.user = jwt.verify(token, JWT_SECRET);
// ── VIEW-AS MODE ──────────────────────────────────────────────────────────
// ── VIEW-AS MODE ──────────────────────────────────────────────────────────
// Jika admin sedang dalam mode "View As Agent", frontend mengirim header
// X-View-As-Agent berisi JWT token yang berisi agent_uuid yang dipilih.
// Pendekatan header lebih reliable dari cookie karena melewati Next.js proxy.
@@ -60,11 +68,11 @@ function requireAuth(req, res, next) {
};
}
} catch (viewErr) {
// Token view-as invalid/expired — abaikan, lanjut sebagai admin normal
// Token view-as invalid/expired — abaikan, lanjut sebagai admin normal
console.warn('[ViewAs] Invalid view-as token, ignoring:', viewErr.message);
}
}
// ─────────────────────────────────────────────────────────────────────────
// ─────────────────────────────────────────────────────────────────────────
next();
} catch (err) {
@@ -75,18 +83,15 @@ function requireAuth(req, res, next) {
const dashboardRoutes = require('./routes/dashboard');
app.use('/api/dashboard', requireAuth, dashboardRoutes);
// ── Health Check ──────────────────────────────────────────────────────────────
// ── Health Check ──────────────────────────────────────────────────────────────
app.get('/api/health', (req, res) => {
res.json({ ok: true, message: 'BackOne Dashboard Backend berjalan!', time: new Date().toISOString() });
});
// ── Start Server ──────────────────────────────────────────────────────────────
// ── Start Server ──────────────────────────────────────────────────────────────
app.listen(PORT, () => {
console.log(`\n🚀 API Server berjalan di http://localhost:${PORT}`);
console.log(`🔌 API Health : http://localhost:${PORT}/api/health\n`);
console.log(`\n🚀 API Server berjalan di http://localhost:${PORT}`);
console.log(`🔌 API Health : http://localhost:${PORT}/api/health\n`);
// Mulai scheduler polling
const { startScheduler } = require('./scheduler');
startScheduler();
});
});