14d412544e
- Added login route with JWT token generation and device validation for non-manager roles. - Implemented clocking functionality with geofence validation and distance calculation. - Created routes for managing workers, including password change and device registration. - Added security status and app blacklist retrieval endpoints. feat: Develop Geofence Management component - Created a Vue component for managing geofences with map integration using Leaflet. - Implemented functionality to draw, save, activate/deactivate, and delete geofences. - Added UI for displaying existing geofences in a table format. feat: Introduce Kill Switch Management component - Developed a calendar-based UI for managing enabled/disabled dates. - Implemented functionality to apply or discard changes to the work schedule. - Added visual indicators for pending changes in the calendar. feat: Create Warning Reporting component - Implemented a reporting interface for failed clock records with search and filter options. - Added detail modal for viewing specific failed record details. - Implemented sorting functionality for the records table.
90 lines
2.8 KiB
JavaScript
90 lines
2.8 KiB
JavaScript
// server.js
|
|
import express from 'express';
|
|
import cors from 'cors';
|
|
import https from 'https';
|
|
import http from 'http';
|
|
import fs from 'fs';
|
|
import path from 'path';
|
|
import { fileURLToPath } from 'url';
|
|
import dotenv from 'dotenv';
|
|
import mysql from 'mysql2/promise';
|
|
import managerRoutes from './managerRoutes.js';
|
|
import workerRoutes from './workerRoutes.js';
|
|
|
|
async function startServer() {
|
|
dotenv.config({ path: path.join(path.dirname(fileURLToPath(import.meta.url)), '.env') });
|
|
|
|
const app = express();
|
|
|
|
const db = mysql.createPool({
|
|
host: process.env.DB_HOST,
|
|
user: process.env.DB_USER,
|
|
password: process.env.DB_PASSWORD,
|
|
database: process.env.DB_NAME,
|
|
port: process.env.DB_PORT,
|
|
waitForConnections: true,
|
|
connectionLimit: 10,
|
|
queueLimit: 0,
|
|
});
|
|
|
|
try {
|
|
const connection = await db.getConnection();
|
|
console.log('Database connected successfully!');
|
|
connection.release();
|
|
} catch (error) {
|
|
console.error('!!! DATABASE CONNECTION FAILED !!!');
|
|
console.error('Error:', error.message);
|
|
process.exit(1);
|
|
}
|
|
|
|
const corsOptions = {
|
|
origin: (origin, callback) => {
|
|
if (!origin || ['http://localhost:5173', 'https://localhost:5173', 'capacitor://localhost', 'ionic://localhost', 'http://localhost', 'https://localhost'].includes(origin) || origin.startsWith('capacitor://') || origin.startsWith('ionic://')) {
|
|
callback(null, true);
|
|
} else {
|
|
console.log('CORS blocked origin:', origin);
|
|
callback(new Error('Not allowed by CORS'));
|
|
}
|
|
},
|
|
credentials: true,
|
|
methods: ['GET', 'POST', 'PUT', 'DELETE', 'OPTIONS'],
|
|
allowedHeaders: ['Content-Type', 'Authorization', 'ngrok-skip-browser-warning'],
|
|
exposedHeaders: ['Content-Range', 'X-Content-Range'],
|
|
};
|
|
|
|
app.use(cors(corsOptions));
|
|
app.use(express.json());
|
|
|
|
app.use('/api/managers', managerRoutes(db));
|
|
app.use('/api', workerRoutes(db));
|
|
|
|
const httpPort = process.env.HTTP_PORT || 3000;
|
|
const httpsPort = process.env.HTTPS_PORT || 3443;
|
|
const sslEnabled = process.env.SSL_ENABLED === 'true';
|
|
|
|
if (sslEnabled) {
|
|
try {
|
|
const currentDir = path.dirname(fileURLToPath(import.meta.url));
|
|
const keyPath = path.join(currentDir, 'key.pem');
|
|
const certPath = path.join(currentDir, 'cert.pem');
|
|
|
|
const httpsOptions = {
|
|
key: fs.readFileSync(keyPath),
|
|
cert: fs.readFileSync(certPath),
|
|
};
|
|
|
|
https.createServer(httpsOptions, app).listen(httpsPort, '0.0.0.0', () => {
|
|
console.log(`🔒 HTTPS Server is running on https://localhost:${httpsPort}`);
|
|
});
|
|
} catch (error) {
|
|
console.error('❌ Failed to start HTTPS server:', error.message);
|
|
}
|
|
}
|
|
|
|
http.createServer(app).listen(httpPort, '0.0.0.0', () => {
|
|
console.log(`🌐 HTTP Server is running on http://localhost:${httpPort}`);
|
|
});
|
|
}
|
|
|
|
startServer();
|