fix: Docker multi-stage build for sqlite3, health endpoint, productValidator exports
- Dockerfile: multi-stage build (builder with python3+g++ for native addons) - Dockerfile: wireguard-tools from edge/community repo - Dockerfile: removed USER appuser (start.sh needs root for wg-quick) - Dockerfile: health check on port 3000 - Added /health HTTP endpoint in index.js for Docker healthcheck - Fixed productValidator.js: added named exports (validateProductName, validateProductPrice) - Added better-sqlite3 as fallback dependency
This commit is contained in:
@@ -1,7 +1,23 @@
|
||||
import Validators from '../../../utils/validators.js';
|
||||
import logger from '../../../utils/logger.js';
|
||||
|
||||
export function validateProductName(name, chatId) {
|
||||
if (!Validators.isValidString(name, 255)) {
|
||||
logger.warn({ chatId, name }, 'Invalid product name');
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
export function validateProductPrice(price, chatId) {
|
||||
if (!Validators.isValidPrice(price)) {
|
||||
logger.warn({ chatId, price }, 'Invalid product price');
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
export default class ProductValidator {
|
||||
|
||||
static validateProduct(product) {
|
||||
if (!Validators.isValidString(product.name, 255)) {
|
||||
return `Ошибка: недопустимое название товара "${product.name}"`;
|
||||
@@ -14,4 +30,4 @@ export default class ProductValidator {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
15
src/index.js
15
src/index.js
@@ -70,3 +70,18 @@ process.on('unhandledRejection', (error) => {
|
||||
});
|
||||
|
||||
logger.info('Bot is running...');
|
||||
|
||||
// Health check endpoint for Docker
|
||||
import http from 'http';
|
||||
const healthServer = http.createServer((req, res) => {
|
||||
if (req.url === '/health') {
|
||||
res.writeHead(200, { 'Content-Type': 'application/json' });
|
||||
res.end(JSON.stringify({ status: 'ok', uptime: process.uptime() }));
|
||||
} else {
|
||||
res.writeHead(404);
|
||||
res.end('Not found');
|
||||
}
|
||||
});
|
||||
healthServer.listen(3000, () => {
|
||||
logger.info({ port: 3000 }, 'Health check server started');
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user