AvanzaCast/scripts/check_token_server_node.mjs
Cesar Mendivil 8b458a3ddf feat: add initial LiveKit Meet integration with utility scripts, configs, and core components
- Add Next.js app structure with base configs, linting, and formatting
- Implement LiveKit Meet page, types, and utility functions
- Add Docker, Compose, and deployment scripts for backend and token server
- Provide E2E and smoke test scaffolding with Puppeteer and Playwright helpers
- Include CSS modules and global styles for UI
- Add postMessage and studio integration utilities
- Update package.json with dependencies and scripts for development and testing
2025-11-20 12:50:38 -07:00

64 lines
2.2 KiB
JavaScript
Executable File

#!/usr/bin/env node
// scripts/check_token_server_node.mjs
// Node script that POSTs to /api/session and shows headers + body for easier debugging
import fetch from 'node-fetch';
import process from 'process';
const server = process.argv[2];
const room = process.argv[3] || 'e2e-room';
const user = process.argv[4] || 'e2e-user';
if (!server) {
console.error('Usage: node scripts/check_token_server_node.mjs <TOKEN_SERVER_BASE_URL> [ROOM] [USERNAME]');
process.exit(2);
}
const sessionUrl = `${server.replace(/\/$/, '')}/api/session`;
console.log('Checking token server at', sessionUrl);
(async () => {
try {
// OPTIONS request to inspect CORS headers
const opt = await fetch(sessionUrl, { method: 'OPTIONS', headers: { 'Origin': 'http://localhost:5176' } });
console.log('\nOPTIONS status', opt.status);
console.log('OPTIONS headers:');
for (const [k, v] of opt.headers) {
console.log(k + ':', v);
}
const resp = await fetch(sessionUrl, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ room, username: user }),
});
console.log('\nPOST status', resp.status);
console.log('Response headers:');
for (const [k, v] of resp.headers) console.log(k + ':', v);
const text = await resp.text();
console.log('\nBody:');
console.log(text);
try {
const json = JSON.parse(text);
console.log('\nParsed JSON keys:', Object.keys(json));
} catch (e) { /* ignore */ }
if (resp.status >= 200 && resp.status < 400) {
let id = null;
try { const js = JSON.parse(text); id = js.id || js.sessionId || js.session_id || null; } catch(e){}
if (id) {
const tokenUrl = `${server.replace(/\/$/, '')}/api/session/${id}/token`;
const tresp = await fetch(tokenUrl);
console.log('\nGET token status', tresp.status);
console.log('GET token headers:');
for (const [k,v] of tresp.headers) console.log(k+':', v);
const tb = await tresp.text();
console.log('\nGET token body:');
console.log(tb);
}
}
} catch (err) {
console.error('Error connecting to token server:', err && err.message ? err.message : err);
process.exit(1);
}
})();