2015-10-26 22:56:53 -07:00
|
|
|
import CyTubeUtil from '../../utilities';
|
|
|
|
|
import { sanitizeText } from '../../xss';
|
2016-07-07 01:11:56 -07:00
|
|
|
import { sendPug } from '../pug';
|
2015-10-26 22:56:53 -07:00
|
|
|
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)) {
|
2015-10-27 20:44:40 -07:00
|
|
|
throw new HTTPError(`"${sanitizeText(req.params.channel)}" is not a valid ` +
|
2015-11-02 20:52:57 -08:00
|
|
|
'channel name.', { status: HTTPStatus.NOT_FOUND });
|
2015-10-26 22:56:53 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const endpoints = ioConfig.getSocketEndpoints();
|
|
|
|
|
if (endpoints.length === 0) {
|
|
|
|
|
throw new HTTPError('No socket.io endpoints configured');
|
|
|
|
|
}
|
|
|
|
|
const socketBaseURL = endpoints[0].url;
|
|
|
|
|
|
2016-07-07 01:11:56 -07:00
|
|
|
sendPug(res, 'channel', {
|
2015-10-26 22:56:53 -07:00
|
|
|
channelName: req.params.channel,
|
|
|
|
|
sioSource: `${socketBaseURL}/socket.io/socket.io.js`
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|