mirror of
https://github.com/Spengreb/sync.git
synced 2026-05-16 20:42:06 +00:00
26 lines
957 B
JavaScript
26 lines
957 B
JavaScript
|
|
import CyTubeUtil from '../../utilities';
|
||
|
|
import { sanitizeText } from '../../xss';
|
||
|
|
import { sendJade } from '../jade';
|
||
|
|
import * as HTTPStatus from '../httpstatus';
|
||
|
|
import { HTTPError } from '../../errors';
|
||
|
|
|
||
|
|
export default function initialize(app, ioConfig) {
|
||
|
|
app.get('/r/:channel', (req, res) => {
|
||
|
|
if (!req.params.channel || !CyTubeUtil.isValidChannelName(req.params.channel)) {
|
||
|
|
throw new HTTPError(`"${sanitizeText(req.params.channel)} is not a valid ` +
|
||
|
|
'channel name.', { status: HTTPStatus.BAD_REQUEST });
|
||
|
|
}
|
||
|
|
|
||
|
|
const endpoints = ioConfig.getSocketEndpoints();
|
||
|
|
if (endpoints.length === 0) {
|
||
|
|
throw new HTTPError('No socket.io endpoints configured');
|
||
|
|
}
|
||
|
|
const socketBaseURL = endpoints[0].url;
|
||
|
|
|
||
|
|
sendJade(res, 'channel', {
|
||
|
|
channelName: req.params.channel,
|
||
|
|
sioSource: `${socketBaseURL}/socket.io/socket.io.js`
|
||
|
|
});
|
||
|
|
});
|
||
|
|
}
|