From b34bd7a4e3e706774170420d33701626b2c4609f Mon Sep 17 00:00:00 2001 From: silverpro89 Date: Wed, 28 Jan 2026 19:54:59 +0700 Subject: [PATCH] update clear cache --- .gitea/workflows/deploy.yml | 4 +- app.js | 12 +++++- controllers/gameController.js | 5 ++- ecosystem.config.js | 77 +---------------------------------- start.json | 4 +- 5 files changed, 21 insertions(+), 81 deletions(-) diff --git a/.gitea/workflows/deploy.yml b/.gitea/workflows/deploy.yml index 2798136..874652c 100644 --- a/.gitea/workflows/deploy.yml +++ b/.gitea/workflows/deploy.yml @@ -42,8 +42,8 @@ jobs: - name: Install dependencies run: | cd /var/www/services/sena_db_api - echo "📦 Installing dependencies with pnpm..." - pnpm install --production + echo "📦 Installing dependencies with npm..." + npm install --production echo "✅ Dependencies installed" - name: Create required directories diff --git a/app.js b/app.js index 21bd561..0c23b16 100644 --- a/app.js +++ b/app.js @@ -76,8 +76,18 @@ app.use(express.json({ limit: '10mb' })); app.use(express.urlencoded({ extended: true, limit: '10mb' })); /** - * Static Files Middleware + * Static Files Middleware with CORS */ +app.use((req, res, next) => { + // Apply CORS headers for static files (images, media, etc.) + if (req.path.match(/\.(jpg|jpeg|png|gif|svg|webp|ico|mp3|mp4|wav|pdf)$/i)) { + res.setHeader('Access-Control-Allow-Origin', '*'); + res.setHeader('Access-Control-Allow-Methods', 'GET, OPTIONS'); + res.setHeader('Access-Control-Allow-Headers', 'Content-Type'); + res.setHeader('Cross-Origin-Resource-Policy', 'cross-origin'); + } + next(); +}); app.use(express.static('public')); /** diff --git a/controllers/gameController.js b/controllers/gameController.js index cca3bef..3aa9196 100644 --- a/controllers/gameController.js +++ b/controllers/gameController.js @@ -18,6 +18,7 @@ class GameController { const cacheKey = `games:list:${page}:${limit}:${type || 'all'}:${is_active || 'all'}:${is_premium || 'all'}:${difficulty_level || 'all'}`; const cached = await cacheUtils.get(cacheKey); + /* if (cached) { return res.json({ success: true, @@ -25,6 +26,7 @@ class GameController { cached: true, }); } + */ const where = {}; if (type) where.type = type; @@ -294,6 +296,7 @@ class GameController { const cacheKey = `games:type:${type}:${only_active}`; const cached = await cacheUtils.get(cacheKey); + /* if (cached) { return res.json({ success: true, @@ -301,7 +304,7 @@ class GameController { cached: true, }); } - + */ const where = { type }; if (only_active === 'true') where.is_active = true; diff --git a/ecosystem.config.js b/ecosystem.config.js index a74eaec..cbb72ab 100644 --- a/ecosystem.config.js +++ b/ecosystem.config.js @@ -9,16 +9,12 @@ module.exports = { { name: 'sena-api', script: './server.js', - instances: 2, // Chạy 2 instances để tận dụng CPU + instances: 1, // Chạy 1 instance để tận dụng CPU exec_mode: 'cluster', env: { NODE_ENV: 'production', PORT: 10001, }, - env_development: { - NODE_ENV: 'development', - PORT: 10001, - }, error_file: './logs/api-error.log', out_file: './logs/api-out.log', log_date_format: 'YYYY-MM-DD HH:mm:ss', @@ -28,75 +24,6 @@ module.exports = { watch: false, max_restarts: 10, min_uptime: '10s', - }, - - // Database Write Worker - { - name: 'worker-db-write', - script: './workers/databaseWriteWorker.js', - instances: 1, - exec_mode: 'fork', - env: { - NODE_ENV: 'production', - }, - env_development: { - NODE_ENV: 'development', - }, - error_file: './logs/worker-db-write-error.log', - out_file: './logs/worker-db-write-out.log', - log_date_format: 'YYYY-MM-DD HH:mm:ss', - merge_logs: true, - max_memory_restart: '512M', - autorestart: true, - watch: false, - max_restarts: 10, - min_uptime: '10s', - }, - - // Lesson Data Fill Worker - { - name: 'worker-lesson-fill', - script: './workers/lessonDataFillWorker.js', - instances: 1, - exec_mode: 'fork', - env: { - NODE_ENV: 'production', - }, - env_development: { - NODE_ENV: 'development', - }, - error_file: './logs/worker-lesson-fill-error.log', - out_file: './logs/worker-lesson-fill-out.log', - log_date_format: 'YYYY-MM-DD HH:mm:ss', - merge_logs: true, - max_memory_restart: '512M', - autorestart: true, - watch: false, - max_restarts: 10, - min_uptime: '10s', - }, - - // Process Data Worker - { - name: 'worker-process-data', - script: './workers/processDataWorker.js', - instances: 2, // Chạy 2 instances để xử lý song song - exec_mode: 'fork', - env: { - NODE_ENV: 'production', - }, - env_development: { - NODE_ENV: 'development', - }, - error_file: './logs/worker-process-data-error.log', - out_file: './logs/worker-process-data-out.log', - log_date_format: 'YYYY-MM-DD HH:mm:ss', - merge_logs: true, - max_memory_restart: '512M', - autorestart: true, - watch: false, - max_restarts: 10, - min_uptime: '10s', - }, + } ], }; diff --git a/start.json b/start.json index c83cb04..e4e55c4 100644 --- a/start.json +++ b/start.json @@ -3,7 +3,7 @@ { "name": "sena-api", "script": "./server.js", - "instances": 2, + "instances": 1, "exec_mode": "cluster", "env": { "NODE_ENV": "production", @@ -68,7 +68,7 @@ { "name": "worker-process-data", "script": "./workers/processDataWorker.js", - "instances": 2, + "instances": 1, "exec_mode": "fork", "env": { "NODE_ENV": "production"