58 lines
2.5 KiB
JavaScript
58 lines
2.5 KiB
JavaScript
|
|
"use strict";
|
||
|
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||
|
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||
|
|
};
|
||
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||
|
|
exports.prisma = void 0;
|
||
|
|
const express_1 = __importDefault(require("express"));
|
||
|
|
const cors_1 = __importDefault(require("cors"));
|
||
|
|
const cookie_parser_1 = __importDefault(require("cookie-parser"));
|
||
|
|
const dotenv_1 = __importDefault(require("dotenv"));
|
||
|
|
const client_1 = require("@prisma/client");
|
||
|
|
// Routes
|
||
|
|
const auth_1 = __importDefault(require("./routes/auth"));
|
||
|
|
const estimates_1 = __importDefault(require("./routes/estimates"));
|
||
|
|
const priceBooks_1 = __importDefault(require("./routes/priceBooks"));
|
||
|
|
const chat_1 = __importDefault(require("./routes/chat"));
|
||
|
|
const settings_1 = __importDefault(require("./routes/settings"));
|
||
|
|
const admin_1 = __importDefault(require("./routes/admin"));
|
||
|
|
const auth_2 = require("./middleware/auth");
|
||
|
|
dotenv_1.default.config();
|
||
|
|
const app = (0, express_1.default)();
|
||
|
|
const prisma = new client_1.PrismaClient();
|
||
|
|
exports.prisma = prisma;
|
||
|
|
const PORT = process.env.PORT || 5000;
|
||
|
|
// Middleware — фронт на :3500, прокси Vite тоже
|
||
|
|
app.use((0, cors_1.default)({ origin: ['http://localhost:3500', 'http://127.0.0.1:3500'], credentials: true }));
|
||
|
|
app.use((0, cookie_parser_1.default)());
|
||
|
|
app.use(express_1.default.json({ limit: '50mb' }));
|
||
|
|
app.use(express_1.default.urlencoded({ extended: true, limit: '50mb' }));
|
||
|
|
// Health check (без авторизации)
|
||
|
|
app.get('/api/health', (req, res) => {
|
||
|
|
res.json({ status: 'ok', timestamp: new Date().toISOString() });
|
||
|
|
});
|
||
|
|
// Auth (публичные)
|
||
|
|
app.use('/api/auth', auth_1.default);
|
||
|
|
// Защищённые маршруты
|
||
|
|
app.use('/api/estimates', auth_2.requireAuth, estimates_1.default);
|
||
|
|
app.use('/api/price-books', auth_2.requireAuth, priceBooks_1.default);
|
||
|
|
app.use('/api/chat', auth_2.requireAuth, chat_1.default);
|
||
|
|
app.use('/api/settings', auth_2.requireAuth, settings_1.default);
|
||
|
|
app.use('/api/admin', auth_2.requireAuth, admin_1.default);
|
||
|
|
// Error handler
|
||
|
|
app.use((err, req, res, next) => {
|
||
|
|
console.error('Error:', err);
|
||
|
|
res.status(500).json({ error: err.message || 'Internal server error' });
|
||
|
|
});
|
||
|
|
// Start server
|
||
|
|
app.listen(PORT, () => {
|
||
|
|
console.log(`Server running on http://localhost:${PORT}`);
|
||
|
|
console.log(`API available at http://localhost:${PORT}/api`);
|
||
|
|
});
|
||
|
|
// Graceful shutdown
|
||
|
|
process.on('SIGTERM', async () => {
|
||
|
|
console.log('SIGTERM received, shutting down...');
|
||
|
|
await prisma.$disconnect();
|
||
|
|
process.exit(0);
|
||
|
|
});
|
||
|
|
//# sourceMappingURL=index.js.map
|