Update frontend login page.jsx และ backend

This commit is contained in:
admin
2025-09-29 13:25:09 +07:00
parent aca3667a9d
commit 7dd5ce8015
52 changed files with 2903 additions and 1289 deletions

View File

@@ -1,6 +1,67 @@
// src/index.js (ESM)
// -------------------
// Node >= 18, Express 4/5 compatible
// FILE: src/index.js (ESM)
// Main entry point for the backend API server
// - Sets up Express app with middleware, routes, error handling
// - Connects to database
// - Starts server and handles graceful shutdown
// ==========================
// Context:
// - Node.js >= 18 (ESM)
// - Express.js 4/5
// - MySQL database (using mysql2/promise)
// ==========================
// Features:
// - CORS with dynamic origin checking
// - Cookie parsing
// - JSON and URL-encoded body parsing
// - Access logging
// - Health, livez, readyz, info endpoints
// - JWT authentication middleware
// - Principal loading middleware
// - Modular route handlers for various resources
// - 404 and error handling middleware
// - Graceful shutdown on SIGTERM/SIGINT
// ==========================
// Assumptions:
// - Environment variables for configuration (e.g., PORT, DB connection, FRONTEND_ORIGIN)
// - Database connection module at ./db/index.js
// - Middleware modules for auth, permissions, principal loading
// - Route modules for different API resources
// - Logs directory exists or can be created
// - Code is written in JavaScript (ESM) and runs in Node.js environment
// - Uses ES6+ features for cleaner and more maintainable code
// ==========================
// Notes:
// - Adjust CORS origins as needed for your frontend applications
// - Ensure proper error handling and logging as per your requirements
// - Customize middleware and routes as per your application's needs
// ==========================
// Best Practices Followed:
// - Assumes existence of necessary database tables and columns
// - Assumes existence of necessary middleware and utility functions
// - Assumes Express.js app is set up to use this router for /api path
// - Assumes existence of necessary environment variables
// - Assumes existence of necessary directories and permissions for file storage
// - Assumes multer is installed and configured
// - Assumes fs and path modules are available for file system operations
// - Assumes sql module is set up for database interactions
// - Assumes middleware modules are correctly implemented and exported
// - Assumes route modules are correctly implemented and exported
// - Uses environment variables for configuration
// - Uses middleware for modular functionality
// - Uses async/await for asynchronous operations
// - Uses try/catch for error handling in async functions (if needed)
// - Uses parameterized queries to prevent SQL injection
// - Uses HTTP status codes for responses (e.g., 404 for not found, 400 for bad request)
// - Uses JSON responses for API endpoints
// - Uses destructuring and default parameters for cleaner function signatures
// - Uses best practices for Express.js route handling
// - Uses modular code structure for maintainability
// - Uses comments for documentation and clarity
// - Uses ES6+ features for cleaner and more maintainable code
// - Uses template literals for SQL query construction
// - Uses array methods for filtering and joining conditions
// - Uses utility functions for common tasks (e.g., building SQL WHERE clauses)
// ==========================
import fs from "node:fs";
import path from "node:path";