PM2 cluster deploy + Redis caching + Nginx gzip + UI polish
- PM2 v6: 2x API cluster + 1x web, zero-downtime reload - Redis cache: 30s TTL on GET /tasks, X-Cache header - Nginx gzip compression - Mobile touch targets 44px - Czech diacritics throughout UI - TaskModal slide-up animation - StatusBadge color dots - GroupSelector emoji icons Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
79
api/package-lock.json
generated
79
api/package-lock.json
generated
@@ -18,6 +18,7 @@
|
||||
"bcrypt": "^6.0.0",
|
||||
"dotenv": "^17.3.1",
|
||||
"fastify": "^5.8.4",
|
||||
"ioredis": "^5.10.1",
|
||||
"pg": "^8.20.0",
|
||||
"redis": "^5.11.0",
|
||||
"uuid": "^13.0.0"
|
||||
@@ -338,6 +339,12 @@
|
||||
"yaml": "^2.4.1"
|
||||
}
|
||||
},
|
||||
"node_modules/@ioredis/commands": {
|
||||
"version": "1.5.1",
|
||||
"resolved": "https://registry.npmjs.org/@ioredis/commands/-/commands-1.5.1.tgz",
|
||||
"integrity": "sha512-JH8ZL/ywcJyR9MmJ5BNqZllXNZQqQbnVZOqpPQqE1vHiFgAw4NHbvE0FOduNU8IX9babitBT46571OnPTT0Zcw==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/@lukeed/ms": {
|
||||
"version": "2.0.2",
|
||||
"resolved": "https://registry.npmjs.org/@lukeed/ms/-/ms-2.0.2.tgz",
|
||||
@@ -660,6 +667,15 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"node_modules/denque": {
|
||||
"version": "2.1.0",
|
||||
"resolved": "https://registry.npmjs.org/denque/-/denque-2.1.0.tgz",
|
||||
"integrity": "sha512-HVQE3AAb/pxF8fQAoiqpvg9i3evqug3hoiwakOyZAwJm+6vZehbkYXZ0l4JxS+I3QxM97v5aaRNhj8v5oBhekw==",
|
||||
"license": "Apache-2.0",
|
||||
"engines": {
|
||||
"node": ">=0.10"
|
||||
}
|
||||
},
|
||||
"node_modules/depd": {
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/depd/-/depd-2.0.0.tgz",
|
||||
@@ -995,6 +1011,30 @@
|
||||
"integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==",
|
||||
"license": "ISC"
|
||||
},
|
||||
"node_modules/ioredis": {
|
||||
"version": "5.10.1",
|
||||
"resolved": "https://registry.npmjs.org/ioredis/-/ioredis-5.10.1.tgz",
|
||||
"integrity": "sha512-HuEDBTI70aYdx1v6U97SbNx9F1+svQKBDo30o0b9fw055LMepzpOOd0Ccg9Q6tbqmBSJaMuY0fB7yw9/vjBYCA==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@ioredis/commands": "1.5.1",
|
||||
"cluster-key-slot": "^1.1.0",
|
||||
"debug": "^4.3.4",
|
||||
"denque": "^2.1.0",
|
||||
"lodash.defaults": "^4.2.0",
|
||||
"lodash.isarguments": "^3.1.0",
|
||||
"redis-errors": "^1.2.0",
|
||||
"redis-parser": "^3.0.0",
|
||||
"standard-as-callback": "^2.1.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=12.22.0"
|
||||
},
|
||||
"funding": {
|
||||
"type": "opencollective",
|
||||
"url": "https://opencollective.com/ioredis"
|
||||
}
|
||||
},
|
||||
"node_modules/ipaddr.js": {
|
||||
"version": "2.3.0",
|
||||
"resolved": "https://registry.npmjs.org/ipaddr.js/-/ipaddr.js-2.3.0.tgz",
|
||||
@@ -1142,6 +1182,18 @@
|
||||
],
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/lodash.defaults": {
|
||||
"version": "4.2.0",
|
||||
"resolved": "https://registry.npmjs.org/lodash.defaults/-/lodash.defaults-4.2.0.tgz",
|
||||
"integrity": "sha512-qjxPLHd3r5DnsdGacqOMU6pb/avJzdh9tFX2ymgoZE27BmjXrNy/y4LoaiTeAb+O3gL8AfpJGtqfX/ae2leYYQ==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/lodash.isarguments": {
|
||||
"version": "3.1.0",
|
||||
"resolved": "https://registry.npmjs.org/lodash.isarguments/-/lodash.isarguments-3.1.0.tgz",
|
||||
"integrity": "sha512-chi4NHZlZqZD18a0imDHnZPrDeBbTtVN7GXMwuGdRH9qotxAjYs3aVLKc7zNOG9eddR5Ksd8rvFEBc9SsggPpg==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/lru-cache": {
|
||||
"version": "11.2.7",
|
||||
"resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-11.2.7.tgz",
|
||||
@@ -1550,6 +1602,27 @@
|
||||
"node": ">= 18"
|
||||
}
|
||||
},
|
||||
"node_modules/redis-errors": {
|
||||
"version": "1.2.0",
|
||||
"resolved": "https://registry.npmjs.org/redis-errors/-/redis-errors-1.2.0.tgz",
|
||||
"integrity": "sha512-1qny3OExCf0UvUV/5wpYKf2YwPcOqXzkwKKSmKHiE6ZMQs5heeE/c8eXK+PNllPvmjgAbfnsbpkGZWy8cBpn9w==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">=4"
|
||||
}
|
||||
},
|
||||
"node_modules/redis-parser": {
|
||||
"version": "3.0.0",
|
||||
"resolved": "https://registry.npmjs.org/redis-parser/-/redis-parser-3.0.0.tgz",
|
||||
"integrity": "sha512-DJnGAeenTdpMEH6uAJRK/uiyEIH9WVsUmoLwzudwGJUwZPp80PDBWPHXSAGNPwNvIXAbe7MSUB1zQFugFml66A==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"redis-errors": "^1.0.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=4"
|
||||
}
|
||||
},
|
||||
"node_modules/require-from-string": {
|
||||
"version": "2.0.2",
|
||||
"resolved": "https://registry.npmjs.org/require-from-string/-/require-from-string-2.0.2.tgz",
|
||||
@@ -1712,6 +1785,12 @@
|
||||
"node": ">= 10.x"
|
||||
}
|
||||
},
|
||||
"node_modules/standard-as-callback": {
|
||||
"version": "2.1.0",
|
||||
"resolved": "https://registry.npmjs.org/standard-as-callback/-/standard-as-callback-2.1.0.tgz",
|
||||
"integrity": "sha512-qoRRSyROncaz1z0mvYqIE4lCd9p2R90i6GxW3uZv5ucSu8tU7B5HXUP1gG8pVZsYNVaXjk8ClXHPttLyxAL48A==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/statuses": {
|
||||
"version": "2.0.2",
|
||||
"resolved": "https://registry.npmjs.org/statuses/-/statuses-2.0.2.tgz",
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
"bcrypt": "^6.0.0",
|
||||
"dotenv": "^17.3.1",
|
||||
"fastify": "^5.8.4",
|
||||
"ioredis": "^5.10.1",
|
||||
"pg": "^8.20.0",
|
||||
"redis": "^5.11.0",
|
||||
"uuid": "^13.0.0"
|
||||
|
||||
@@ -1,40 +1,67 @@
|
||||
// Task Team — API Server — 2026-03-29
|
||||
require('dotenv').config();
|
||||
const Fastify = require('fastify');
|
||||
const cors = require('@fastify/cors');
|
||||
const jwt = require('@fastify/jwt');
|
||||
const { Pool } = require('pg');
|
||||
require("dotenv").config();
|
||||
const Fastify = require("fastify");
|
||||
const cors = require("@fastify/cors");
|
||||
const jwt = require("@fastify/jwt");
|
||||
const { Pool } = require("pg");
|
||||
const Redis = require("ioredis");
|
||||
|
||||
const app = Fastify({ logger: true });
|
||||
|
||||
// Database pool
|
||||
const pool = new Pool({
|
||||
connectionString: process.env.DATABASE_URL || 'postgresql://taskteam:TaskTeam2026!@10.10.10.10:5432/taskteam'
|
||||
connectionString: process.env.DATABASE_URL || "postgresql://taskteam:TaskTeam2026!@10.10.10.10:5432/taskteam"
|
||||
});
|
||||
|
||||
// Redis client
|
||||
const redis = new Redis(process.env.REDIS_URL || "redis://:Redis2026!@10.10.10.10:6379");
|
||||
|
||||
redis.on("connect", () => {
|
||||
app.log.info("Redis connected");
|
||||
});
|
||||
redis.on("error", (err) => {
|
||||
app.log.error("Redis error: " + err.message);
|
||||
});
|
||||
|
||||
// Plugins
|
||||
app.register(cors, { origin: true });
|
||||
app.register(jwt, { secret: process.env.JWT_SECRET || 'taskteam-jwt-secret-2026' });
|
||||
app.register(jwt, { secret: process.env.JWT_SECRET || "taskteam-jwt-secret-2026" });
|
||||
|
||||
// Decorate with db
|
||||
app.decorate('db', pool);
|
||||
// Decorate with db and redis
|
||||
app.decorate("db", pool);
|
||||
app.decorate("redis", redis);
|
||||
|
||||
// Health check
|
||||
app.get('/health', async () => ({ status: 'ok', timestamp: new Date().toISOString() }));
|
||||
app.get("/health", async () => ({
|
||||
status: "ok",
|
||||
timestamp: new Date().toISOString(),
|
||||
pid: process.pid,
|
||||
redis: redis.status
|
||||
}));
|
||||
|
||||
// Register routes
|
||||
app.register(require('./routes/tasks'), { prefix: '/api/v1' });
|
||||
app.register(require('./routes/groups'), { prefix: '/api/v1' });
|
||||
app.register(require('./routes/auth'), { prefix: '/api/v1' });
|
||||
app.register(require('./routes/connectors'), { prefix: '/api/v1' });
|
||||
app.register(require('./routes/connectors/odoo'), { prefix: '/api/v1' });
|
||||
app.register(require('./routes/chat'), { prefix: '/api/v1' });
|
||||
app.register(require("./routes/tasks"), { prefix: "/api/v1" });
|
||||
app.register(require("./routes/groups"), { prefix: "/api/v1" });
|
||||
app.register(require("./routes/auth"), { prefix: "/api/v1" });
|
||||
app.register(require("./routes/connectors"), { prefix: "/api/v1" });
|
||||
app.register(require("./routes/connectors/odoo"), { prefix: "/api/v1" });
|
||||
app.register(require("./routes/chat"), { prefix: "/api/v1" });
|
||||
|
||||
// Graceful shutdown
|
||||
const shutdown = async (signal) => {
|
||||
app.log.info(`Received ${signal}, shutting down gracefully...`);
|
||||
await redis.quit();
|
||||
await pool.end();
|
||||
process.exit(0);
|
||||
};
|
||||
process.on("SIGINT", () => shutdown("SIGINT"));
|
||||
process.on("SIGTERM", () => shutdown("SIGTERM"));
|
||||
|
||||
// Start
|
||||
const start = async () => {
|
||||
try {
|
||||
await app.listen({ port: process.env.PORT || 3000, host: '0.0.0.0' });
|
||||
console.log('Task Team API listening on port ' + (process.env.PORT || 3000));
|
||||
await app.listen({ port: process.env.PORT || 3000, host: "0.0.0.0" });
|
||||
console.log("Task Team API listening on port " + (process.env.PORT || 3000) + " (pid: " + process.pid + ")");
|
||||
} catch (err) {
|
||||
app.log.error(err);
|
||||
process.exit(1);
|
||||
|
||||
@@ -1,84 +1,154 @@
|
||||
// Task Team — Tasks CRUD — 2026-03-29
|
||||
// Task Team — Tasks CRUD with Redis Caching — 2026-03-29
|
||||
const CACHE_TTL = 30; // seconds
|
||||
const CACHE_PREFIX = "taskteam:tasks:";
|
||||
|
||||
async function taskRoutes(app) {
|
||||
// List tasks
|
||||
app.get('/tasks', async (req, reply) => {
|
||||
|
||||
// Helper: build cache key from query params
|
||||
function cacheKey(query) {
|
||||
const { status, group_id, limit = 50, offset = 0 } = query;
|
||||
return CACHE_PREFIX + "list:" + [status || "", group_id || "", limit, offset].join(":");
|
||||
}
|
||||
|
||||
// Helper: invalidate all task list caches
|
||||
async function invalidateTaskCaches() {
|
||||
try {
|
||||
const keys = await app.redis.keys(CACHE_PREFIX + "*");
|
||||
if (keys.length > 0) {
|
||||
await app.redis.del(...keys);
|
||||
app.log.info("Invalidated " + keys.length + " task cache keys");
|
||||
}
|
||||
} catch (err) {
|
||||
app.log.warn("Cache invalidation error: " + err.message);
|
||||
}
|
||||
}
|
||||
|
||||
// List tasks (cached)
|
||||
app.get("/tasks", async (req, reply) => {
|
||||
const key = cacheKey(req.query);
|
||||
|
||||
// Try cache first
|
||||
try {
|
||||
const cached = await app.redis.get(key);
|
||||
if (cached) {
|
||||
reply.header("X-Cache", "HIT");
|
||||
return JSON.parse(cached);
|
||||
}
|
||||
} catch (err) {
|
||||
app.log.warn("Cache read error: " + err.message);
|
||||
}
|
||||
|
||||
const { status, group_id, limit = 50, offset = 0 } = req.query;
|
||||
let query = 'SELECT t.*, tg.name as group_name, tg.color as group_color, tg.icon as group_icon FROM tasks t LEFT JOIN task_groups tg ON t.group_id = tg.id WHERE 1=1';
|
||||
let query = "SELECT t.*, tg.name as group_name, tg.color as group_color, tg.icon as group_icon FROM tasks t LEFT JOIN task_groups tg ON t.group_id = tg.id WHERE 1=1";
|
||||
const params = [];
|
||||
if (status) { params.push(status); query += ` AND t.status = $${params.length}`; }
|
||||
if (group_id) { params.push(group_id); query += ` AND t.group_id = $${params.length}`; }
|
||||
query += ' ORDER BY t.scheduled_at ASC NULLS LAST, t.priority DESC, t.created_at DESC';
|
||||
query += " ORDER BY t.scheduled_at ASC NULLS LAST, t.priority DESC, t.created_at DESC";
|
||||
params.push(limit); query += ` LIMIT $${params.length}`;
|
||||
params.push(offset); query += ` OFFSET $${params.length}`;
|
||||
const { rows } = await app.db.query(query, params);
|
||||
return { data: rows, total: rows.length };
|
||||
const result = { data: rows, total: rows.length };
|
||||
|
||||
// Store in cache
|
||||
try {
|
||||
await app.redis.set(key, JSON.stringify(result), "EX", CACHE_TTL);
|
||||
} catch (err) {
|
||||
app.log.warn("Cache write error: " + err.message);
|
||||
}
|
||||
|
||||
reply.header("X-Cache", "MISS");
|
||||
return result;
|
||||
});
|
||||
|
||||
// Get single task
|
||||
app.get('/tasks/:id', async (req) => {
|
||||
// Get single task (cached)
|
||||
app.get("/tasks/:id", async (req, reply) => {
|
||||
const key = CACHE_PREFIX + "detail:" + req.params.id;
|
||||
|
||||
try {
|
||||
const cached = await app.redis.get(key);
|
||||
if (cached) {
|
||||
reply.header("X-Cache", "HIT");
|
||||
return JSON.parse(cached);
|
||||
}
|
||||
} catch (err) {
|
||||
app.log.warn("Cache read error: " + err.message);
|
||||
}
|
||||
|
||||
const { rows } = await app.db.query(
|
||||
'SELECT t.*, tg.name as group_name, tg.color as group_color FROM tasks t LEFT JOIN task_groups tg ON t.group_id = tg.id WHERE t.id = $1',
|
||||
"SELECT t.*, tg.name as group_name, tg.color as group_color FROM tasks t LEFT JOIN task_groups tg ON t.group_id = tg.id WHERE t.id = $1",
|
||||
[req.params.id]
|
||||
);
|
||||
if (!rows.length) throw { statusCode: 404, message: 'Task not found' };
|
||||
return { data: rows[0] };
|
||||
if (!rows.length) throw { statusCode: 404, message: "Task not found" };
|
||||
const result = { data: rows[0] };
|
||||
|
||||
try {
|
||||
await app.redis.set(key, JSON.stringify(result), "EX", CACHE_TTL);
|
||||
} catch (err) {
|
||||
app.log.warn("Cache write error: " + err.message);
|
||||
}
|
||||
|
||||
reply.header("X-Cache", "MISS");
|
||||
return result;
|
||||
});
|
||||
|
||||
// Create task
|
||||
app.post('/tasks', async (req) => {
|
||||
// Create task (invalidates cache)
|
||||
app.post("/tasks", async (req) => {
|
||||
const { title, description, status, group_id, priority, scheduled_at, due_at, assigned_to } = req.body;
|
||||
const { rows } = await app.db.query(
|
||||
`INSERT INTO tasks (title, description, status, group_id, priority, scheduled_at, due_at, assigned_to)
|
||||
VALUES ($1, $2, $3, $4, $5, $6, $7, $8) RETURNING *`,
|
||||
[title, description || '', status || 'pending', group_id, priority || 'medium', scheduled_at, due_at, assigned_to || []]
|
||||
[title, description || "", status || "pending", group_id, priority || "medium", scheduled_at, due_at, assigned_to || []]
|
||||
);
|
||||
await invalidateTaskCaches();
|
||||
return { data: rows[0] };
|
||||
});
|
||||
|
||||
// Update task
|
||||
app.put('/tasks/:id', async (req) => {
|
||||
// Update task (invalidates cache)
|
||||
app.put("/tasks/:id", async (req) => {
|
||||
const fields = req.body;
|
||||
const sets = [];
|
||||
const params = [];
|
||||
let i = 1;
|
||||
for (const [key, value] of Object.entries(fields)) {
|
||||
if (['title','description','status','group_id','priority','scheduled_at','due_at','assigned_to','completed_at'].includes(key)) {
|
||||
if (["title","description","status","group_id","priority","scheduled_at","due_at","assigned_to","completed_at"].includes(key)) {
|
||||
sets.push(`${key} = $${i}`);
|
||||
params.push(value);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
if (fields.status === 'completed' && !fields.completed_at) {
|
||||
sets.push(`completed_at = NOW()`);
|
||||
if (fields.status === "completed" && !fields.completed_at) {
|
||||
sets.push("completed_at = NOW()");
|
||||
}
|
||||
sets.push(`updated_at = NOW()`);
|
||||
sets.push("updated_at = NOW()");
|
||||
params.push(req.params.id);
|
||||
const { rows } = await app.db.query(
|
||||
`UPDATE tasks SET ${sets.join(', ')} WHERE id = $${i} RETURNING *`, params
|
||||
`UPDATE tasks SET ${sets.join(", ")} WHERE id = $${i} RETURNING *`, params
|
||||
);
|
||||
if (!rows.length) throw { statusCode: 404, message: 'Task not found' };
|
||||
if (!rows.length) throw { statusCode: 404, message: "Task not found" };
|
||||
await invalidateTaskCaches();
|
||||
return { data: rows[0] };
|
||||
});
|
||||
|
||||
// Delete task
|
||||
app.delete('/tasks/:id', async (req) => {
|
||||
const { rowCount } = await app.db.query('DELETE FROM tasks WHERE id = $1', [req.params.id]);
|
||||
if (!rowCount) throw { statusCode: 404, message: 'Task not found' };
|
||||
return { status: 'deleted' };
|
||||
// Delete task (invalidates cache)
|
||||
app.delete("/tasks/:id", async (req) => {
|
||||
const { rowCount } = await app.db.query("DELETE FROM tasks WHERE id = $1", [req.params.id]);
|
||||
if (!rowCount) throw { statusCode: 404, message: "Task not found" };
|
||||
await invalidateTaskCaches();
|
||||
return { status: "deleted" };
|
||||
});
|
||||
|
||||
// Task comments
|
||||
app.get('/tasks/:id/comments', async (req) => {
|
||||
app.get("/tasks/:id/comments", async (req) => {
|
||||
const { rows } = await app.db.query(
|
||||
'SELECT * FROM task_comments WHERE task_id = $1 ORDER BY created_at ASC', [req.params.id]
|
||||
"SELECT * FROM task_comments WHERE task_id = $1 ORDER BY created_at ASC", [req.params.id]
|
||||
);
|
||||
return { data: rows };
|
||||
});
|
||||
|
||||
app.post('/tasks/:id/comments', async (req) => {
|
||||
app.post("/tasks/:id/comments", async (req) => {
|
||||
const { content, is_ai } = req.body;
|
||||
const { rows } = await app.db.query(
|
||||
'INSERT INTO task_comments (task_id, content, is_ai) VALUES ($1, $2, $3) RETURNING *',
|
||||
"INSERT INTO task_comments (task_id, content, is_ai) VALUES ($1, $2, $3) RETURNING *",
|
||||
[req.params.id, content, is_ai || false]
|
||||
);
|
||||
return { data: rows[0] };
|
||||
|
||||
Reference in New Issue
Block a user