31 lines
1.1 KiB
JavaScript
31 lines
1.1 KiB
JavaScript
const express = require('express');
|
|
const app = express();
|
|
const { UserModel, PropertyModel, expToUp } = global.config;
|
|
|
|
// Настраиваем сервер для выдачи статических файлов
|
|
app.use(express.static('public'));
|
|
|
|
// Эндпоинт для получения данных профиля
|
|
app.get('/profile/:id', async (req, res) => {
|
|
const id = req.params.id;
|
|
const user = await UserModel.findByPk(id);
|
|
const property = await PropertyModel.findByPk(id);
|
|
|
|
if (!user) return res.status(404).send({ error: 'Пользователь не найден' });
|
|
|
|
res.send({
|
|
username: user.username,
|
|
level: user.level,
|
|
exp: user.exp,
|
|
expToNextLevel: expToUp[user.level],
|
|
money: user.money,
|
|
house: property.house ? property.house.name : "Бездомный",
|
|
car: property.car1 ? property.car1.name : "Пешком",
|
|
mobile: property.mobile ? property.mobile.name : "Нет",
|
|
});
|
|
});
|
|
|
|
// Запуск сервера
|
|
const PORT = process.env.PORT || 3000;
|
|
app.listen(PORT, () => console.log(`Сервер запущен на порту ${PORT}`));
|