added public watch parties with cloudflared

This commit is contained in:
2026-01-04 19:59:37 +01:00
parent d9c1ba3d27
commit 5fe0e319b9
20 changed files with 1426 additions and 458 deletions

View File

@@ -41,6 +41,76 @@ fastify.addHook("preHandler", async (request) => {
}
});
const roomService = require('./dist/api/rooms/rooms.service');
fastify.addHook('onRequest', async (req, reply) => {
const isTunnel =
!!req.headers['cf-connecting-ip'] ||
!!req.headers['cf-ray'];
if (!isTunnel) return;
if (req.url.startsWith('/public/') ||
req.url.startsWith('/views/') ||
req.url.startsWith('/src/')) {
return;
}
if (req.url.startsWith('/room')) {
const urlParams = new URLSearchParams(req.url.split('?')[1]);
const roomId = urlParams.get('id');
if (!roomId) {
return reply.code(404).send({ error: 'Room ID required' });
}
const room = roomService.getRoom(roomId);
if (!room || room.exposed !== true) {
return reply.code(404).send({ error: 'Room not found' });
}
return;
}
const wsMatch = req.url.match(/^\/ws\/room\/([a-f0-9]+)/);
if (wsMatch) {
const roomId = wsMatch[1];
const room = roomService.getRoom(roomId);
if (!room || room.exposed !== true) {
return reply.code(404).send({ error: 'Room not found' });
}
return;
}
const apiMatch = req.url.match(/^\/api\/rooms\/([a-f0-9]+)/);
if (apiMatch) {
const roomId = apiMatch[1];
const room = roomService.getRoom(roomId);
if (!room || room.exposed !== true) {
return reply.code(404).send({ error: 'Room not found' });
}
return;
}
const allowedEndpoints = [
'/api/watch/stream',
'/api/proxy',
'/api/extensions',
'/api/search'
];
for (const endpoint of allowedEndpoints) {
if (req.url.startsWith(endpoint)) {
console.log('[Tunnel] ✓ Allowing utility endpoint:', endpoint);
return;
}
}
return reply.code(404).send({ error: 'Not found' });
});
fastify.register(require("@fastify/static"), {
root: path.join(__dirname, "public"),
prefix: "/public/",