import express from 'express';
const app = express();
const BASE_URL = process.env.TIUN_API_BASE || 'https://api-sandbox.tiun.live';
const API_KEY = process.env.TIUN_API_KEY;
app.get('/api/premium-content', async (req, res) => {
const sessionId = req.headers['x-session-id'];
if (!sessionId) {
// missing session id → reject as no access
return;
}
const tiunResponse = await fetch(
`${BASE_URL}/live_api/s2s/v1/sessions/${sessionId}/status`,
{
method: 'PATCH',
headers: { 'X-TIUN-API-KEY': API_KEY },
},
);
if (tiunResponse.status === 200) {
// session valid → serve the premium content
} else if (tiunResponse.status === 404) {
// session invalid, expired, or user out of funds → deny
} else {
// unexpected error from tiun → fail closed
}
});