});
};
+ const httpNotFound = res => {
+ res.writeHead(404, { 'Content-Type': 'application/json' });
+ res.end(JSON.stringify({ error: 'Not found' }));
+ };
+
app.use(setRequestId);
app.use(setRemoteAddress);
app.use(allowCrossDomain);
});
app.get('/api/v1/streaming/hashtag', (req, res) => {
- streamFrom(`timeline:hashtag:${req.query.tag.toLowerCase()}`, req, streamToHttp(req, res), streamHttpEnd(req), true);
+ const { tag } = req.query;
+
+ if (!tag || tag.length === 0) {
+ httpNotFound(res);
+ return;
+ }
+
+ streamFrom(`timeline:hashtag:${tag.toLowerCase()}`, req, streamToHttp(req, res), streamHttpEnd(req), true);
});
app.get('/api/v1/streaming/hashtag/local', (req, res) => {
- streamFrom(`timeline:hashtag:${req.query.tag.toLowerCase()}:local`, req, streamToHttp(req, res), streamHttpEnd(req), true);
+ const { tag } = req.query;
+
+ if (!tag || tag.length === 0) {
+ httpNotFound(res);
+ return;
+ }
+
+ streamFrom(`timeline:hashtag:${tag.toLowerCase()}:local`, req, streamToHttp(req, res), streamHttpEnd(req), true);
});
app.get('/api/v1/streaming/list', (req, res) => {
authorizeListAccess(listId, req, authorized => {
if (!authorized) {
- res.writeHead(404, { 'Content-Type': 'application/json' });
- res.end(JSON.stringify({ error: 'Not found' }));
+ httpNotFound(res);
return;
}
streamFrom(channel, req, streamToWs(req, ws), streamWsEnd(req, ws, subscriptionHeartbeat(channel)), true);
break;
case 'hashtag':
+ if (!location.query.tag || location.query.tag.length === 0) {
+ ws.close();
+ return;
+ }
+
streamFrom(`timeline:hashtag:${location.query.tag.toLowerCase()}`, req, streamToWs(req, ws), streamWsEnd(req, ws), true);
break;
case 'hashtag:local':
+ if (!location.query.tag || location.query.tag.length === 0) {
+ ws.close();
+ return;
+ }
+
streamFrom(`timeline:hashtag:${location.query.tag.toLowerCase()}:local`, req, streamToWs(req, ws), streamWsEnd(req, ws), true);
break;
case 'list':