Spaces:
Sleeping
Sleeping
File size: 1,662 Bytes
100ccc8 48f6a1e 100ccc8 48f6a1e 100ccc8 2c5c634 48f6a1e 1c19df4 22eaaa9 100ccc8 48f6a1e 100ccc8 22eaaa9 48f6a1e 22eaaa9 100ccc8 48f6a1e 100ccc8 48f6a1e 100ccc8 48f6a1e 2c5c634 48f6a1e 100ccc8 | 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 | const http = require('http');
// --- 💎 ОБЛАЧНЫЙ СЕЙФ 9.3 ---
let cloudData = { score: 0, power: 1 };
const server = http.createServer((req, res) => {
// 🛡️ ГИПЕР-ЩИТ CORS
res.setHeader('Access-Control-Allow-Origin', '*');
res.setHeader('Access-Control-Allow-Methods', 'GET, POST, OPTIONS');
res.setHeader('Access-Control-Allow-Headers', 'Content-Type');
if (req.method === 'OPTIONS') {
res.writeHead(204);
res.end();
return;
}
// 📥 1. ПОЛУЧИТЬ СЧЕТ (GET /get_score)
if (req.method === 'GET' && req.url === '/get_score') {
res.writeHead(200, { 'Content-Type': 'application/json' });
res.end(JSON.stringify(cloudData));
return;
}
// 📤 2. СОХРАНИТЬ КЛИКИ (POST /save)
if (req.method === 'POST' && req.url === '/save') {
let body = '';
req.on('data', chunk => { body += chunk.toString(); });
req.on('end', () => {
try {
const newData = JSON.parse(body);
cloudData.score = newData.score;
cloudData.power = newData.power;
console.log("💎 Баланс обновлен: " + cloudData.score);
res.writeHead(200, { 'Content-Type': 'application/json' });
res.end(JSON.stringify({ status: "OK" }));
} catch (e) {
res.writeHead(400); res.end("Error");
}
});
return;
}
res.writeHead(404);
res.end("Not Found");
});
// 🚀 ПОРТ 7860
server.listen(7860, () => {
console.log('Emerald Cloud 9.3 Active');
});
|