callback-server.js•1.99 kB
const http = require('http');
const url = require('url');
const server = http.createServer((req, res) => {
const parsedUrl = url.parse(req.url, true);
if (parsedUrl.pathname === '/callback' && parsedUrl.query.code) {
// CORS headers
res.setHeader('Access-Control-Allow-Origin', '*');
res.setHeader('Access-Control-Allow-Methods', 'GET');
res.setHeader('Access-Control-Allow-Headers', 'Content-Type');
// Return the code in a simple HTML page
res.writeHead(200, { 'Content-Type': 'text/html; charset=utf-8' });
res.end(`
<!DOCTYPE html>
<html>
<head>
<title>Spotify Auth Success</title>
<style>
body { font-family: Arial, sans-serif; text-align: center; padding: 50px; }
.success { color: #1db954; font-size: 24px; margin-bottom: 20px; }
.code { background: #f0f0f0; padding: 10px; border-radius: 5px; font-family: monospace; word-break: break-all; }
.copy-btn { background: #1db954; color: white; border: none; padding: 10px 20px; border-radius: 5px; cursor: pointer; margin-top: 10px; }
</style>
</head>
<body>
<div class="success">✅ Autenticação Spotify Concluída!</div>
<p>Copie o código abaixo:</p>
<div class="code" id="code">${parsedUrl.query.code}</div>
<button class="copy-btn" onclick="navigator.clipboard.writeText('${parsedUrl.query.code}')">Copiar Código</button>
<script>
// Auto-copy to clipboard
navigator.clipboard.writeText('${parsedUrl.query.code}').then(() => {
console.log('Código copiado automaticamente!');
});
</script>
</body>
</html>
`);
} else {
res.writeHead(404, { 'Content-Type': 'text/plain' });
res.end('Not Found');
}
});
const PORT = 8080;
server.listen(PORT, () => {
console.log(`🎵 Callback server rodando na porta ${PORT}`);
console.log(`📡 Aguardando callback do Spotify...`);
});