-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
36 lines (29 loc) · 1.15 KB
/
server.js
File metadata and controls
36 lines (29 loc) · 1.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
// server.js
// Запуск сервера и подключение маршрутов
const express = require('express');
const tasksRoutes = require('./routes/tasks');
const app = express();
const PORT = process.env.PORT || 5000;
// Мидлвар для парсинга JSON
app.use(express.json());
// Подключаем маршруты для задач
app.use('/tasks', tasksRoutes);
// Обработка 404 для несуществующих маршрутов
app.use((req, res) => {
res.status(404).json({ error: 'Маршрут не найден' });
});
// Глобальный обработчик ошибок (простейший)
app.use((err, req, res, next) => {
console.error(err.stack);
res.status(500).json({ error: 'Что-то пошло не так на сервере' });
});
// Запуск
app.listen(PORT, () => {
console.log(`Сервер запущен на http://localhost:${PORT}`);
console.log('Доступные эндпоинты:');
console.log('GET /tasks');
console.log('GET /tasks/:id');
console.log('POST /tasks');
console.log('PUT /tasks/:id');
console.log('DELETE /tasks/:id');
});