-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathlocal-server.js
More file actions
59 lines (48 loc) · 1.93 KB
/
local-server.js
File metadata and controls
59 lines (48 loc) · 1.93 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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
const express = require('express');
const path = require('path');
const os = require('os');
const app = express();
const PORT = 3000;
// Статические файлы
app.use(express.static(__dirname));
// Главная страница
app.get('/', (req, res) => {
res.sendFile(path.join(__dirname, 'index.html'));
});
// Получаем локальные IP адреса
function getLocalIPs() {
const interfaces = os.networkInterfaces();
const ips = [];
Object.keys(interfaces).forEach(interfaceName => {
interfaces[interfaceName].forEach(interface => {
if (interface.family === 'IPv4' && !interface.internal) {
ips.push(interface.address);
}
});
});
return ips;
}
// Запуск сервера
app.listen(PORT, '0.0.0.0', () => {
const localIPs = getLocalIPs();
console.log('🚀 Advanced Calculator Server запущен!');
console.log('');
console.log('📱 Доступен по адресам:');
console.log(` Локально: http://localhost:${PORT}`);
console.log(` Локально: http://127.0.0.1:${PORT}`);
localIPs.forEach(ip => {
console.log(` В сети: http://${ip}:${PORT}`);
});
console.log('');
console.log('💡 Советы:');
console.log(' - Используйте IP адреса "В сети" для доступа с других устройств');
console.log(' - Убедитесь, что устройства в одной Wi-Fi сети');
console.log(' - Проверьте настройки брандмауэра');
console.log('');
console.log('⏹️ Для остановки: Ctrl+C');
});
// Обработка завершения
process.on('SIGINT', () => {
console.log('\n🛑 Сервер остановлен');
process.exit(0);
});