-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
68 lines (60 loc) · 2.31 KB
/
Copy pathserver.js
File metadata and controls
68 lines (60 loc) · 2.31 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
60
61
62
63
64
65
66
67
68
/**
* IPTV PRO - Standalone HTTP Server
* Requires ZERO external dependencies. Bu faylni boshqarish uchun faqat Node.js kerak.
* Run with: node server.js
*/
const http = require('http');
const fs = require('fs');
const path = require('path');
const PORT = process.env.PORT || 8080;
const MIME_TYPES = {
'.html': 'text/html',
'.js': 'text/javascript',
'.css': 'text/css',
'.json': 'application/json',
'.png': 'image/png',
'.jpg': 'image/jpg',
'.svg': 'image/svg+xml',
'.ico': 'image/x-icon',
'.m3u': 'audio/mpegurl',
'.m3u8': 'application/vnd.apple.mpegurl'
};
const server = http.createServer((request, response) => {
console.log(`>> So'rov keldi: ${request.url}`);
let filePath = '.' + request.url;
if (filePath === './') {
filePath = './index.html';
} else {
// Parametrlarni tozalash (masalan: ?stream=url)
filePath = filePath.split('?')[0];
}
const extname = String(path.extname(filePath)).toLowerCase();
const contentType = MIME_TYPES[extname] || 'application/octet-stream';
fs.readFile(filePath, (error, content) => {
if (error) {
if(error.code === 'ENOENT') {
response.writeHead(404, { 'Content-Type': 'text/html' });
response.end('<h1>404 - Fayl topilmadi</h1><p>IPTV PRO tizimi: Ushbu manzil mavjud emas.</p>', 'utf-8');
} else {
response.writeHead(500);
response.end('Server xatosi: '+error.code+' ..\n');
}
} else {
// CORS ruxsatnomalari - Global ruxsat
response.writeHead(200, {
'Content-Type': contentType,
'Access-Control-Allow-Origin': '*',
'Cache-Control': 'no-cache'
});
response.end(content, 'utf-8');
}
});
});
server.listen(PORT, '0.0.0.0', () => {
console.log(`\n=========================================`);
console.log(`🚀 IPTV PRO Server muvaffaqiyatli ishga tushdi!`);
console.log(`=========================================`);
console.log(`\nShu kompyuterdan kirish uchun: \n👉 http://localhost:${PORT}`);
console.log(`\nUbuntu Server tarmoqdan (Global) kirish uchun IP manzilingiz orqali: \n👉 http://<SERVER_IP>:${PORT}\n`);
console.log(`To'xtatish uchun: CTRL + C bosing.`);
});