update clear cache
All checks were successful
Deploy to Production / deploy (push) Successful in 20s
All checks were successful
Deploy to Production / deploy (push) Successful in 20s
This commit is contained in:
@@ -42,8 +42,8 @@ jobs:
|
|||||||
- name: Install dependencies
|
- name: Install dependencies
|
||||||
run: |
|
run: |
|
||||||
cd /var/www/services/sena_db_api
|
cd /var/www/services/sena_db_api
|
||||||
echo "📦 Installing dependencies with pnpm..."
|
echo "📦 Installing dependencies with npm..."
|
||||||
pnpm install --production
|
npm install --production
|
||||||
echo "✅ Dependencies installed"
|
echo "✅ Dependencies installed"
|
||||||
|
|
||||||
- name: Create required directories
|
- name: Create required directories
|
||||||
|
|||||||
12
app.js
12
app.js
@@ -76,8 +76,18 @@ app.use(express.json({ limit: '10mb' }));
|
|||||||
app.use(express.urlencoded({ extended: true, 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'));
|
app.use(express.static('public'));
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ class GameController {
|
|||||||
const cacheKey = `games:list:${page}:${limit}:${type || 'all'}:${is_active || 'all'}:${is_premium || 'all'}:${difficulty_level || 'all'}`;
|
const cacheKey = `games:list:${page}:${limit}:${type || 'all'}:${is_active || 'all'}:${is_premium || 'all'}:${difficulty_level || 'all'}`;
|
||||||
|
|
||||||
const cached = await cacheUtils.get(cacheKey);
|
const cached = await cacheUtils.get(cacheKey);
|
||||||
|
/*
|
||||||
if (cached) {
|
if (cached) {
|
||||||
return res.json({
|
return res.json({
|
||||||
success: true,
|
success: true,
|
||||||
@@ -25,6 +26,7 @@ class GameController {
|
|||||||
cached: true,
|
cached: true,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
const where = {};
|
const where = {};
|
||||||
if (type) where.type = type;
|
if (type) where.type = type;
|
||||||
@@ -294,6 +296,7 @@ class GameController {
|
|||||||
const cacheKey = `games:type:${type}:${only_active}`;
|
const cacheKey = `games:type:${type}:${only_active}`;
|
||||||
|
|
||||||
const cached = await cacheUtils.get(cacheKey);
|
const cached = await cacheUtils.get(cacheKey);
|
||||||
|
/*
|
||||||
if (cached) {
|
if (cached) {
|
||||||
return res.json({
|
return res.json({
|
||||||
success: true,
|
success: true,
|
||||||
@@ -301,7 +304,7 @@ class GameController {
|
|||||||
cached: true,
|
cached: true,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
const where = { type };
|
const where = { type };
|
||||||
if (only_active === 'true') where.is_active = true;
|
if (only_active === 'true') where.is_active = true;
|
||||||
|
|
||||||
|
|||||||
@@ -9,16 +9,12 @@ module.exports = {
|
|||||||
{
|
{
|
||||||
name: 'sena-api',
|
name: 'sena-api',
|
||||||
script: './server.js',
|
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',
|
exec_mode: 'cluster',
|
||||||
env: {
|
env: {
|
||||||
NODE_ENV: 'production',
|
NODE_ENV: 'production',
|
||||||
PORT: 10001,
|
PORT: 10001,
|
||||||
},
|
},
|
||||||
env_development: {
|
|
||||||
NODE_ENV: 'development',
|
|
||||||
PORT: 10001,
|
|
||||||
},
|
|
||||||
error_file: './logs/api-error.log',
|
error_file: './logs/api-error.log',
|
||||||
out_file: './logs/api-out.log',
|
out_file: './logs/api-out.log',
|
||||||
log_date_format: 'YYYY-MM-DD HH:mm:ss',
|
log_date_format: 'YYYY-MM-DD HH:mm:ss',
|
||||||
@@ -28,75 +24,6 @@ module.exports = {
|
|||||||
watch: false,
|
watch: false,
|
||||||
max_restarts: 10,
|
max_restarts: 10,
|
||||||
min_uptime: '10s',
|
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',
|
|
||||||
},
|
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
{
|
{
|
||||||
"name": "sena-api",
|
"name": "sena-api",
|
||||||
"script": "./server.js",
|
"script": "./server.js",
|
||||||
"instances": 2,
|
"instances": 1,
|
||||||
"exec_mode": "cluster",
|
"exec_mode": "cluster",
|
||||||
"env": {
|
"env": {
|
||||||
"NODE_ENV": "production",
|
"NODE_ENV": "production",
|
||||||
@@ -68,7 +68,7 @@
|
|||||||
{
|
{
|
||||||
"name": "worker-process-data",
|
"name": "worker-process-data",
|
||||||
"script": "./workers/processDataWorker.js",
|
"script": "./workers/processDataWorker.js",
|
||||||
"instances": 2,
|
"instances": 1,
|
||||||
"exec_mode": "fork",
|
"exec_mode": "fork",
|
||||||
"env": {
|
"env": {
|
||||||
"NODE_ENV": "production"
|
"NODE_ENV": "production"
|
||||||
|
|||||||
Reference in New Issue
Block a user