Nahrát soubory do „/“
This commit is contained in:
37
server.js
Normal file
37
server.js
Normal file
@@ -0,0 +1,37 @@
|
||||
const express = require('express');
|
||||
const cors = require('cors');
|
||||
const app = express();
|
||||
const PORT = 8080;
|
||||
|
||||
app.use(cors());
|
||||
app.use(express.json());
|
||||
|
||||
// Sem si budeme ukládat poslední přijatou skladbu
|
||||
let currentSongData = {
|
||||
artist: "Čekám na Spotify...",
|
||||
title: "Spusťte hudbu",
|
||||
coverImg: null,
|
||||
progressTime: "0:00/0:00",
|
||||
ad: "false"
|
||||
};
|
||||
|
||||
// 1. Endpoint, kam Chrome rozšíření posílá data (POST)
|
||||
app.post('/endpoint', (req, res) => {
|
||||
if (req.body && req.body.artist) {
|
||||
currentSongData = req.body; // Uložíme data do paměti
|
||||
console.log("--- New Song Received ---");
|
||||
console.log(`Interpret: ${currentSongData.artist}`);
|
||||
console.log(`Skladba: ${currentSongData.title}`);
|
||||
console.log(`Čas: ${currentSongData.progressTime} | Reklama: ${currentSongData.ad}`);
|
||||
}
|
||||
res.sendStatus(200);
|
||||
});
|
||||
|
||||
// 2. Endpoint, ze kterého si Python widget čte data (GET)
|
||||
app.get('/endpoint', (req, res) => {
|
||||
res.json(currentSongData);
|
||||
});
|
||||
|
||||
app.listen(PORT, '0.0.0.0', () => {
|
||||
console.log(`Server běží a poslouchá na portu ${PORT}...`);
|
||||
});
|
||||
Reference in New Issue
Block a user