fixed cut overlays and solved the docker duplication thing
This commit is contained in:
parent
f4327c3c40
commit
0d3a273e22
@ -1,7 +1,7 @@
|
||||
FROM node:18-alpine
|
||||
|
||||
# Install wget and dumb-init for proper signal handling
|
||||
RUN apk add --no-cache wget dumb-init
|
||||
# Install wget for health checks
|
||||
RUN apk add --no-cache wget
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
@ -33,6 +33,5 @@ USER nodejs
|
||||
|
||||
EXPOSE 3000
|
||||
|
||||
# Use dumb-init to handle signals properly and prevent zombie processes
|
||||
ENTRYPOINT ["dumb-init", "--"]
|
||||
# Use exec form to ensure PID 1 is node process
|
||||
CMD ["node", "server.js"]
|
||||
@ -5,7 +5,6 @@
|
||||
"main": "server.js",
|
||||
"scripts": {
|
||||
"start": "node server.js",
|
||||
"dev": "nodemon server.js",
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"keywords": [
|
||||
|
||||
@ -54,8 +54,8 @@
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
/* Ensure circle markers are visible */
|
||||
path.leaflet-interactive {
|
||||
/* Ensure circle markers are visible - but NOT cut polygons */
|
||||
path.leaflet-interactive:not(.cut-polygon) {
|
||||
stroke: #fff;
|
||||
stroke-opacity: 1;
|
||||
stroke-width: 2;
|
||||
@ -107,7 +107,15 @@ path.leaflet-interactive {
|
||||
/* Cut polygons - allow dynamic opacity (higher specificity to override) */
|
||||
.leaflet-container path.leaflet-interactive.cut-polygon {
|
||||
stroke-width: 2px !important;
|
||||
/* Allow JavaScript to control fill-opacity - remove !important */
|
||||
/* Allow JavaScript to control fill-opacity - explicitly do NOT override it */
|
||||
stroke: currentColor !important;
|
||||
stroke-opacity: 0.8 !important;
|
||||
}
|
||||
|
||||
/* Additional specificity rule for cut polygons to ensure JS opacity takes precedence */
|
||||
path.leaflet-interactive.cut-polygon {
|
||||
/* Do not set fill-opacity here - let JavaScript control it */
|
||||
stroke-width: 2px;
|
||||
}
|
||||
|
||||
/* Marker being moved */
|
||||
|
||||
@ -37,6 +37,10 @@
|
||||
border-radius: 50%;
|
||||
background: rgba(255, 68, 68, 0.3);
|
||||
animation: pulse-ring 2s ease-out infinite;
|
||||
/* Position the pulse at the tip of the marker */
|
||||
top: 24px;
|
||||
left: 0;
|
||||
transform-origin: center center;
|
||||
}
|
||||
|
||||
@keyframes bounce-marker {
|
||||
|
||||
@ -184,12 +184,8 @@ export class CutManager {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a cut on the map (enhanced to support multiple cuts)
|
||||
*/
|
||||
/**
|
||||
* Display a cut on the map (enhanced to support multiple cuts)
|
||||
*/
|
||||
// ...existing code...
|
||||
|
||||
displayCut(cutData, autoDisplayed = false) {
|
||||
if (!this.map) {
|
||||
console.error('Map not initialized');
|
||||
@ -226,14 +222,41 @@ export class CutManager {
|
||||
const geojsonData = typeof normalizedCut.geojson === 'string' ?
|
||||
JSON.parse(normalizedCut.geojson) : normalizedCut.geojson;
|
||||
|
||||
// Parse opacity value - ensure it's a number between 0 and 1
|
||||
let opacityValue = parseFloat(normalizedCut.opacity);
|
||||
|
||||
// Validate opacity is within range
|
||||
if (isNaN(opacityValue) || opacityValue < 0 || opacityValue > 1) {
|
||||
opacityValue = 0.3; // Default fallback
|
||||
console.log(`Invalid opacity value (${normalizedCut.opacity}), using default: ${opacityValue}`);
|
||||
}
|
||||
|
||||
const cutLayer = L.geoJSON(geojsonData, {
|
||||
style: {
|
||||
color: normalizedCut.color || '#3388ff',
|
||||
fillColor: normalizedCut.color || '#3388ff',
|
||||
fillOpacity: parseFloat(normalizedCut.opacity) || 0.3,
|
||||
fillOpacity: opacityValue,
|
||||
weight: 2,
|
||||
opacity: 1,
|
||||
opacity: 0.8, // Stroke opacity - keeping this slightly transparent for better visibility
|
||||
className: 'cut-polygon'
|
||||
},
|
||||
// Add onEachFeature to apply styles to each individual feature
|
||||
onEachFeature: function (feature, layer) {
|
||||
// Apply styles directly to the layer to ensure they override CSS
|
||||
if (layer.setStyle) {
|
||||
layer.setStyle({
|
||||
fillOpacity: opacityValue,
|
||||
color: normalizedCut.color || '#3388ff',
|
||||
fillColor: normalizedCut.color || '#3388ff',
|
||||
weight: 2,
|
||||
opacity: 0.8
|
||||
});
|
||||
}
|
||||
|
||||
// Add cut-polygon class to the path element
|
||||
if (layer._path) {
|
||||
layer._path.classList.add('cut-polygon');
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@ -249,6 +272,15 @@ export class CutManager {
|
||||
|
||||
cutLayer.addTo(this.map);
|
||||
|
||||
// Ensure cut-polygon class is applied to all path elements after adding to map
|
||||
cutLayer.eachLayer(function(layer) {
|
||||
if (layer._path) {
|
||||
layer._path.classList.add('cut-polygon');
|
||||
// Force the fill-opacity style to ensure it overrides CSS
|
||||
layer._path.style.fillOpacity = opacityValue;
|
||||
}
|
||||
});
|
||||
|
||||
// Store in both tracking systems
|
||||
this.cutLayers.set(normalizedCut.id, cutLayer);
|
||||
this.displayedCuts.set(normalizedCut.id, normalizedCut);
|
||||
@ -257,7 +289,7 @@ export class CutManager {
|
||||
this.currentCut = normalizedCut;
|
||||
this.currentCutLayer = cutLayer;
|
||||
|
||||
console.log(`Displayed cut: ${normalizedCut.name} (ID: ${normalizedCut.id})`);
|
||||
console.log(`Displayed cut: ${normalizedCut.name} (ID: ${normalizedCut.id}) with opacity: ${opacityValue} (raw: ${normalizedCut.opacity})`);
|
||||
return true;
|
||||
|
||||
} catch (error) {
|
||||
@ -266,9 +298,8 @@ export class CutManager {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Hide the currently displayed cut (legacy method - now hides all cuts)
|
||||
*/
|
||||
// ...existing code...
|
||||
|
||||
hideCut() {
|
||||
this.hideAllCuts();
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -1,6 +1,16 @@
|
||||
// At the very top of the file, before any requires
|
||||
const startTime = Date.now();
|
||||
|
||||
// Use a more robust check for duplicate execution
|
||||
if (global.__serverInitialized) {
|
||||
console.log(`[INIT] Server already initialized - EXITING`);
|
||||
return;
|
||||
}
|
||||
global.__serverInitialized = true;
|
||||
|
||||
// Prevent duplicate execution
|
||||
if (require.main !== module) {
|
||||
console.log('Server.js being imported, not executed directly');
|
||||
console.log('[INIT] Server.js being imported, not executed directly - EXITING');
|
||||
return;
|
||||
}
|
||||
|
||||
@ -12,10 +22,6 @@ const cookieParser = require('cookie-parser');
|
||||
const crypto = require('crypto');
|
||||
const fetch = require('node-fetch');
|
||||
|
||||
// Debug: Check if server.js is being loaded multiple times
|
||||
const serverInstanceId = Math.random().toString(36).substr(2, 9);
|
||||
console.log(`[DEBUG] Server.js PID:${process.pid} instance ${serverInstanceId} loading at ${new Date().toISOString()}`);
|
||||
|
||||
// Import configuration and utilities
|
||||
const config = require('./config');
|
||||
const logger = require('./utils/logger');
|
||||
@ -24,8 +30,14 @@ const { apiLimiter } = require('./middleware/rateLimiter');
|
||||
const { cacheBusting } = require('./utils/cacheBusting');
|
||||
const { initializeEmailService } = require('./services/email');
|
||||
|
||||
// Initialize Express app
|
||||
// Initialize Express app - only create once
|
||||
if (global.__expressApp) {
|
||||
console.log('[INIT] Express app already created - EXITING');
|
||||
return;
|
||||
}
|
||||
|
||||
const app = express();
|
||||
global.__expressApp = app;
|
||||
|
||||
// Trust proxy for Cloudflare
|
||||
app.set('trust proxy', true);
|
||||
@ -33,8 +45,8 @@ app.set('trust proxy', true);
|
||||
// Cookie parser
|
||||
app.use(cookieParser());
|
||||
|
||||
// Session configuration
|
||||
app.use(session({
|
||||
// Session configuration - only initialize once
|
||||
const sessionMiddleware = session({
|
||||
secret: config.session.secret,
|
||||
resave: false,
|
||||
saveUninitialized: false,
|
||||
@ -44,36 +56,34 @@ app.use(session({
|
||||
// Use a custom session ID generator to avoid conflicts
|
||||
return crypto.randomBytes(16).toString('hex');
|
||||
}
|
||||
}));
|
||||
});
|
||||
|
||||
app.use(sessionMiddleware);
|
||||
|
||||
// Build dynamic CSP configuration
|
||||
const buildConnectSrc = () => {
|
||||
const sources = ["'self'"];
|
||||
|
||||
// Add MkDocs URLs from config
|
||||
if (config.mkdocs?.url) {
|
||||
sources.push(config.mkdocs.url);
|
||||
// Add NocoDB API URL
|
||||
if (config.nocodb.apiUrl) {
|
||||
try {
|
||||
const nocodbUrl = new URL(config.nocodb.apiUrl);
|
||||
sources.push(`${nocodbUrl.protocol}//${nocodbUrl.host}`);
|
||||
} catch (e) {
|
||||
// Invalid URL, skip
|
||||
}
|
||||
}
|
||||
|
||||
// Add localhost ports from environment
|
||||
const mkdocsPort = process.env.MKDOCS_PORT || '4000';
|
||||
const mkdocsSitePort = process.env.MKDOCS_SITE_SERVER_PORT || '4002';
|
||||
|
||||
sources.push(`http://localhost:${mkdocsPort}`);
|
||||
sources.push(`http://localhost:${mkdocsSitePort}`);
|
||||
|
||||
// Add City of Edmonton Socrata API
|
||||
// Add Edmonton Open Data Portal
|
||||
sources.push('https://data.edmonton.ca');
|
||||
|
||||
// Add Stadia Maps for better tile coverage
|
||||
sources.push('https://tiles.stadiamaps.com');
|
||||
// Add Nominatim for geocoding
|
||||
sources.push('https://nominatim.openstreetmap.org');
|
||||
|
||||
// Add production domains if in production
|
||||
if (config.isProduction || process.env.NODE_ENV === 'production') {
|
||||
// Add the main domain from environment
|
||||
const mainDomain = process.env.DOMAIN || 'cmlite.org';
|
||||
sources.push(`https://${mainDomain}`);
|
||||
sources.push('https://cmlite.org'); // Fallback
|
||||
// Add localhost for development
|
||||
if (!config.isProduction) {
|
||||
sources.push('http://localhost:*');
|
||||
sources.push('ws://localhost:*');
|
||||
}
|
||||
|
||||
return sources;
|
||||
@ -95,15 +105,27 @@ app.use(helmet({
|
||||
// CORS configuration
|
||||
app.use(cors({
|
||||
origin: function(origin, callback) {
|
||||
// Allow requests with no origin (like mobile apps or curl requests)
|
||||
// Allow requests with no origin (like Postman or server-to-server)
|
||||
if (!origin) return callback(null, true);
|
||||
|
||||
const allowedOrigins = config.cors.allowedOrigins;
|
||||
if (allowedOrigins.includes(origin) || allowedOrigins.includes('*')) {
|
||||
// In production, be more restrictive
|
||||
if (config.isProduction) {
|
||||
const allowedOrigins = [
|
||||
`https://${config.domain}`,
|
||||
`https://map.${config.domain}`,
|
||||
`https://docs.${config.domain}`,
|
||||
`https://admin.${config.domain}`
|
||||
];
|
||||
|
||||
if (allowedOrigins.includes(origin)) {
|
||||
callback(null, true);
|
||||
} else {
|
||||
callback(new Error('Not allowed by CORS'));
|
||||
}
|
||||
} else {
|
||||
// In development, allow localhost
|
||||
callback(null, true);
|
||||
}
|
||||
},
|
||||
credentials: true,
|
||||
methods: ['GET', 'POST', 'PUT', 'DELETE', 'OPTIONS'],
|
||||
@ -136,25 +158,24 @@ app.get('/api/version', (req, res) => {
|
||||
// Proxy endpoint for MkDocs search
|
||||
app.get('/api/docs-search', async (req, res) => {
|
||||
try {
|
||||
const mkdocsUrl = config.mkdocs?.url || `http://localhost:${process.env.MKDOCS_SITE_SERVER_PORT || '4002'}`;
|
||||
logger.info(`Fetching search index from: ${mkdocsUrl}/search/search_index.json`);
|
||||
|
||||
const response = await fetch(`${mkdocsUrl}/search/search_index.json`);
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`Failed to fetch search index: ${response.status}`);
|
||||
}
|
||||
const docsUrl = config.isProduction ?
|
||||
`https://docs.${config.domain}/search/search_index.json` :
|
||||
'http://localhost:8000/search/search_index.json';
|
||||
|
||||
const response = await fetch(docsUrl);
|
||||
const data = await response.json();
|
||||
res.json(data);
|
||||
} catch (error) {
|
||||
logger.error('Error fetching search index:', error);
|
||||
logger.error('Failed to fetch docs search index:', error);
|
||||
res.status(500).json({ error: 'Failed to fetch search index' });
|
||||
}
|
||||
});
|
||||
|
||||
// Initialize email service
|
||||
// Initialize email service - only once
|
||||
if (!global.__emailInitialized) {
|
||||
initializeEmailService();
|
||||
global.__emailInitialized = true;
|
||||
}
|
||||
|
||||
// Import and setup routes
|
||||
require('./routes')(app);
|
||||
@ -162,19 +183,25 @@ require('./routes')(app);
|
||||
// Error handling middleware
|
||||
app.use((err, req, res, next) => {
|
||||
logger.error('Unhandled error:', err);
|
||||
|
||||
// Don't leak error details in production
|
||||
const message = config.isProduction ?
|
||||
'Internal server error' :
|
||||
err.message || 'Internal server error';
|
||||
|
||||
res.status(err.status || 500).json({
|
||||
success: false,
|
||||
error: message
|
||||
res.status(500).json({
|
||||
error: 'Internal server error',
|
||||
message: config.isProduction ? 'An error occurred' : err.message
|
||||
});
|
||||
});
|
||||
|
||||
// Start server
|
||||
// Add a simple health check endpoint early in the middleware stack (before other middlewares)
|
||||
app.get('/health', (req, res) => {
|
||||
res.status(200).json({
|
||||
status: 'healthy',
|
||||
timestamp: new Date().toISOString(),
|
||||
uptime: process.uptime()
|
||||
});
|
||||
});
|
||||
|
||||
// Only start server if not already started
|
||||
if (!global.__serverStarted) {
|
||||
global.__serverStarted = true;
|
||||
|
||||
const server = app.listen(config.port, () => {
|
||||
logger.info(`
|
||||
╔════════════════════════════════════════╗
|
||||
@ -182,10 +209,10 @@ const server = app.listen(config.port, () => {
|
||||
╠════════════════════════════════════════╣
|
||||
║ Status: Running ║
|
||||
║ Port: ${config.port} ║
|
||||
║ Environment: ${config.nodeEnv} ║
|
||||
║ Environment: ${config.isProduction ? 'production' : 'development'} ║
|
||||
║ Project ID: ${config.nocodb.projectId} ║
|
||||
║ Table ID: ${config.nocodb.tableId} ║
|
||||
║ Login Sheet: ${config.nocodb.loginSheetId || 'Not Configured'} ║
|
||||
║ Login Sheet: ${config.nocodb.loginSheetId} ║
|
||||
║ PID: ${process.pid} ║
|
||||
║ Time: ${new Date().toISOString()} ║
|
||||
╚════════════════════════════════════════╝
|
||||
@ -211,7 +238,7 @@ process.on('SIGINT', () => {
|
||||
|
||||
// Handle uncaught exceptions
|
||||
process.on('uncaughtException', (err) => {
|
||||
logger.error('Uncaught exception:', err);
|
||||
logger.error('Uncaught Exception:', err);
|
||||
process.exit(1);
|
||||
});
|
||||
|
||||
@ -220,5 +247,6 @@ process.on('unhandledRejection', (reason, promise) => {
|
||||
logger.error('Unhandled Rejection at:', promise, 'reason:', reason);
|
||||
process.exit(1);
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = app;
|
||||
@ -1,20 +1,10 @@
|
||||
const winston = require('winston');
|
||||
const config = require('../config');
|
||||
|
||||
// Debug: Check if logger is being created multiple times
|
||||
const instanceId = Math.random().toString(36).substr(2, 9);
|
||||
console.log(`[DEBUG] Creating logger instance ${instanceId} at ${new Date().toISOString()}`);
|
||||
|
||||
// Ensure we only create one logger instance
|
||||
if (global.appLogger) {
|
||||
console.log(`[DEBUG] Reusing existing logger instance`);
|
||||
module.exports = global.appLogger;
|
||||
return;
|
||||
}
|
||||
|
||||
// Create the logger only once
|
||||
const logger = winston.createLogger({
|
||||
level: config.isProduction ? 'info' : 'debug',
|
||||
defaultMeta: { service: 'bnkops-map', instanceId },
|
||||
defaultMeta: { service: 'bnkops-map' },
|
||||
transports: [
|
||||
new winston.transports.Console({
|
||||
format: winston.format.combine(
|
||||
@ -50,7 +40,4 @@ if (config.isProduction) {
|
||||
}));
|
||||
}
|
||||
|
||||
// Store logger globally to prevent multiple instances
|
||||
global.appLogger = logger;
|
||||
|
||||
module.exports = logger;
|
||||
Loading…
x
Reference in New Issue
Block a user