commented out social bot list check
This commit is contained in:
parent
137a34ceb9
commit
87acd65d2d
3 changed files with 44 additions and 1 deletions
|
@ -3,6 +3,22 @@ const logger = require('winston');
|
||||||
const SERVE = 'SERVE';
|
const SERVE = 'SERVE';
|
||||||
const SHOW = 'SHOW';
|
const SHOW = 'SHOW';
|
||||||
|
|
||||||
|
function headersMatchesSocialBotList (headers) {
|
||||||
|
const socialBotList = [
|
||||||
|
'facebookexternalhit',
|
||||||
|
'Twitterbot',
|
||||||
|
];
|
||||||
|
const userAgent = headers['user-agent'];
|
||||||
|
for (let i = 0; i < socialBotList.length; i++) {
|
||||||
|
const socialBot = socialBotList[i];
|
||||||
|
if (userAgent.indexOf(socialBot) >= 0) {
|
||||||
|
logger.debug('headers on request matched this bot:', socialBot);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
function clientAcceptsHtml ({accept}) {
|
function clientAcceptsHtml ({accept}) {
|
||||||
return accept && accept.match(/text\/html/);
|
return accept && accept.match(/text\/html/);
|
||||||
};
|
};
|
||||||
|
@ -19,6 +35,12 @@ function clientWantsAsset ({accept, range}) {
|
||||||
|
|
||||||
const determineResponseType = (hasFileExtension, headers) => {
|
const determineResponseType = (hasFileExtension, headers) => {
|
||||||
let responseType;
|
let responseType;
|
||||||
|
logger.debug('headers:', headers);
|
||||||
|
// return early with 'show' if headers match the list
|
||||||
|
if (headersMatchesSocialBotList(headers)) {
|
||||||
|
// return SHOW;
|
||||||
|
}
|
||||||
|
// fallback logic if not on the list
|
||||||
if (hasFileExtension) {
|
if (hasFileExtension) {
|
||||||
responseType = SERVE; // assume a serve request if file extension is present
|
responseType = SERVE; // assume a serve request if file extension is present
|
||||||
if (clientAcceptsHtml(headers)) { // if the request comes from a browser, change it to a show request
|
if (clientAcceptsHtml(headers)) { // if the request comes from a browser, change it to a show request
|
||||||
|
|
|
@ -28,7 +28,7 @@ module.exports = (app) => {
|
||||||
app.get('/api/claim/data/:claimName/:claimId', claimData);
|
app.get('/api/claim/data/:claimName/:claimId', claimData);
|
||||||
app.get('/api/claim/get/:name/:claimId', claimGet);
|
app.get('/api/claim/get/:name/:claimId', claimGet);
|
||||||
app.get('/api/claim/list/:name', claimList);
|
app.get('/api/claim/list/:name', claimList);
|
||||||
app.post('/api/claim/long-id', claimLongId);
|
app.post('/api/claim/long-id', claimLongId); // should be a get
|
||||||
app.post('/api/claim/publish', multipartMiddleware, claimPublish);
|
app.post('/api/claim/publish', multipartMiddleware, claimPublish);
|
||||||
app.get('/api/claim/resolve/:name/:claimId', claimResolve);
|
app.get('/api/claim/resolve/:name/:claimId', claimResolve);
|
||||||
app.get('/api/claim/short-id/:longId/:name', claimShortId);
|
app.get('/api/claim/short-id/:longId/:name', claimShortId);
|
||||||
|
|
21
test/test.html
Normal file
21
test/test.html
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
<!doctype html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport"
|
||||||
|
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
|
||||||
|
<meta http-equiv="X-UA-Compatible" content="ie=edge">
|
||||||
|
<title>Document</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<img src="https://media.giphy.com/media/vwEHGjx71HSytx5mY8/giphy-facebook_s.jpg" alt="test embed"/>
|
||||||
|
<p>no identifier, no ending</p>
|
||||||
|
<img src="https://dev1.spee.ch/typingcat" alt="no identifier, no ending"/>
|
||||||
|
<p>no identifier, yes ending</p>
|
||||||
|
<img src="https://dev1.spee.ch/typingcat.gif" alt="no identifier, yes ending"/>
|
||||||
|
<p>yes identifier, no ending</p>
|
||||||
|
<img src="https://dev1.spee.ch/8/typingcat" alt="yes identifier, no ending"/>
|
||||||
|
<p>yes identifier, yes ending</p>
|
||||||
|
<img src="https://dev1.spee.ch/8/typingcat.gif" alt="yes identifier, yes ending"/>
|
||||||
|
</body>
|
||||||
|
</html>
|
Loading…
Reference in a new issue