Skip to content
This repository was archived by the owner on May 6, 2020. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
27e643d
Merge pull request #32 from jeffjose/master
erwinmombay Jan 10, 2018
9e3b375
Implement support for new Google Cache URL format.
pietergreyling Jan 22, 2018
9ca0bbb
Implement fix for " "If-Modified-Since" and "ETag" header " issue.
pietergreyling Jan 31, 2018
744409d
fix canonical URL validation for valid characters
juanchaur Feb 16, 2018
21a9c5a
Merge fix canonical URL validation for valid characters #42
pietergreyling Feb 16, 2018
80e6198
middleware to encode url for valid urls
juanchaur Feb 19, 2018
a36afba
Adding warning when multiple amphtml links found in canonical page
Feb 20, 2018
aace86b
Merge pull request #45 from juanchaur1/addWarningToDuplicateAmpLinks
erwinmombay Feb 28, 2018
6a6d36c
Additional support for multiple amphtml links in the canonical
pietergreyling Mar 9, 2018
7a256d5
Adding Bing Ads
jeffjose Mar 13, 2018
d98d214
adding Branch.png and version bump
jeffjose Mar 20, 2018
85d5d36
Version bump + ignore all google.com domains
jeffjose Mar 27, 2018
9afb0d6
Merge pull request #44 from juanchaur/fixEncodeURLInEntryPoint
pietergreyling Apr 30, 2018
79bf8ba
Applied fix for urls that contain accented characters to /api routes.
pietergreyling Apr 30, 2018
d7a2af1
Fixing LICENSE
jeffjose Jun 25, 2018
324aaf2
Added support for 'CMS' tag in vendors.json. Added support for BlueKa…
philkrie Aug 8, 2018
00bf93c
Merge branch 'master' of https://github.com/philkrie/ampbench
philkrie Aug 8, 2018
bc7e3cc
Merge pull request #3 from philkrie/master
jeffjose Aug 10, 2018
c1a8fb6
version bump
jeffjose Aug 10, 2018
916d757
Merge branch 'master' of github.com:jeffjose/ampbench
jeffjose Aug 10, 2018
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions ampbench_handlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ function validate(route, user_agent, user_agent_name, req, res, on_validate_call
canonical_parsed_return.result = ''; // make a result field

let canonical_url_found = canonical_parsed_return.canonical_url,
amphtml_url_found = canonical_parsed_return.amphtml_url,
amphtml_url_found = canonical_parsed_return.amphtml_urls, // could be multiples
fetch_duration_amp = http_response.duration_in_milliseconds,
fetch_duration_canonical = http_response_canonical.duration_in_milliseconds,
fetch_duration_amp_cache = 0, fetch_status_amp_cache = '';
Expand All @@ -141,17 +141,21 @@ function validate(route, user_agent, user_agent_name, req, res, on_validate_call
canonical_parsed_return.canonical_url = benchlib.make_url_href(
canonical_url_found, canonical_url_found);
}
if ('' !== amphtml_url_found) {
canonical_parsed_return.result += '[AMP link found in Canonical page]';
if (url_to_validate !== amphtml_url_found) { // amp link not pointing back!!!
if ('' !== amphtml_url_found[0]) {
canonical_parsed_return.result += '[AMP link found in Canonical page]';
if (!amphtml_url_found.includes(url_to_validate)) { // amp link not pointing back!!!
canonical_parsed_return.status = CHECK_FAIL;
canonical_parsed_return.result += '[FAIL: AMP link in Canonical page does not refer to the current AMP page]';
} else {
} else if(amphtml_url_found.length > 1) {
canonical_parsed_return.status = CHECK_WARN;
canonical_parsed_return.result += '[WARNING: Multiple AMP links found in Canonical page]';
} else {
canonical_parsed_return.status = CHECK_PASS;
canonical_parsed_return.result += '[AMP link in Canonical page refers to the current AMP page]';
}
canonical_parsed_return.amphtml_url = benchlib.make_url_href(
amphtml_url_found, amphtml_url_found);
amphtml_url_found[0], amphtml_url_found[0]); // could be multiples, if so take the 1st one
canonical_parsed_return.amphtml_urls = benchlib.make_url_href_list(canonical_parsed_return.amphtml_urls);
} else {
canonical_parsed_return.status = CHECK_WARN;
let _can_result =
Expand Down
182 changes: 142 additions & 40 deletions ampbench_lib.js

Large diffs are not rendered by default.

129 changes: 73 additions & 56 deletions ampbench_routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const handlers = require('./ampbench_handlers.js');

const VERSION_STRING = '[AMPBENCH:V.1.0]';

function version_msg(msg){
function version_msg(msg) {
return VERSION_STRING + '[' + new Date().toISOString() + '] ' + msg;
}

Expand Down Expand Up @@ -58,14 +58,14 @@ function consoleLogRequestResponse(req, res) {
}

function ifdef(v) { // useful for outputting potentially undefined variable values
if(v)
if (v)
return v;
else
return '';
}

function format_dashes(dash_count) { // needs: const S = require('string');
return ( S(('- ').repeat(dash_count)).s );
return (S(('- ').repeat(dash_count)).s);
}

function print_dashes(dash_count) { // needs: const S = require('string');
Expand All @@ -83,19 +83,24 @@ const
CHECK_WARN = 'WARNING',
CHECK_NONE = 'UNKNOWN';
const // http://www.tutorialspoint.com/html/html_colors.htm
CHECK_FAIL_CSS = '<span style="color: red; ">' + CHECK_FAIL + '</span>',
CHECK_PASS_CSS = '<span style="color: #41c40f; ">' + CHECK_PASS + '</span>',
CHECK_INFO_CSS = '<span style="color: #c530ac; ">' + CHECK_INFO + '</span>',
CHECK_WARN_CSS = '<span style="color: orange; ">' + CHECK_WARN + '</span>',
CHECK_NONE_CSS = '<span style="color: orange; ">' + CHECK_NONE + '</span>';
CHECK_FAIL_CSS = '<span style="color: red; ">' + CHECK_FAIL + '</span>',
CHECK_PASS_CSS = '<span style="color: #41c40f; ">' + CHECK_PASS + '</span>',
CHECK_INFO_CSS = '<span style="color: #c530ac; ">' + CHECK_INFO + '</span>',
CHECK_WARN_CSS = '<span style="color: orange; ">' + CHECK_WARN + '</span>',
CHECK_NONE_CSS = '<span style="color: orange; ">' + CHECK_NONE + '</span>';
const
get_check_status_css = (status) => {
switch(status) {
case CHECK_FAIL: return CHECK_FAIL_CSS;
case CHECK_PASS: return CHECK_PASS_CSS;
case CHECK_INFO: return CHECK_INFO_CSS;
case CHECK_WARN: return CHECK_WARN_CSS;
default: return CHECK_NONE_CSS;
switch (status) {
case CHECK_FAIL:
return CHECK_FAIL_CSS;
case CHECK_PASS:
return CHECK_PASS_CSS;
case CHECK_INFO:
return CHECK_INFO_CSS;
case CHECK_WARN:
return CHECK_WARN_CSS;
default:
return CHECK_NONE_CSS;
}
};

Expand All @@ -110,7 +115,7 @@ const http = require('http');
const https = require('https');
const url = require('url');
const util = require('util');
const inspect_obj = (obj) => {return util.inspect(obj, { showHidden: true, depth: null })};
const inspect_obj = (obj) => { return util.inspect(obj, { showHidden: true, depth: null }) };
const S = require('string');

const express = require('express');
Expand All @@ -129,6 +134,13 @@ const results_template = fs.readFileSync(__dirname + '/views/results.hbs', 'utf8
// TODO: WIP20160426 - bulk support routes
// const multi_url_template = fs.readFileSync(__dirname + '/views/multi_url.hbs', 'utf8');

app.use(function(req, res, next) {
if (req.query && req.query.url) {
req.query.url = encodeURI(req.query.url);
}
next();
});

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// ERRORS
//
Expand Down Expand Up @@ -197,6 +209,9 @@ app.get('/version', (req, res) => {
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

function assert_url(req, res) { // handle bad urls
if (req.query && req.query.url) {
req.query.url = encodeURI(req.query.url);
}
let url_to_validate = req.query.url || '';
if (!benchlib.check_url_is_valid(url_to_validate)) {
console.log(version_msg(
Expand All @@ -205,8 +220,7 @@ function assert_url(req, res) { // handle bad urls
req.path + ' ' + url_to_validate));
let _err = {
error: true,
error_message:
'[ERROR: INVALID URL] Please check the formatting of the requested URL',
error_message: '[ERROR: INVALID URL] Please check the formatting of the requested URL',
error_url: url_to_validate,
error_request_host: req.hostname,
error_request_path: req.path,
Expand Down Expand Up @@ -339,12 +353,12 @@ app.get('/debug/', (req, res) => {
res.status(200).send(version_msg('No AMP URL parameter found.'));
} else {
_debug_results =
'\n==> GET: ' + amp_url + '\n\n' + '{"User-Agent": '
+ benchlib.UA_AMPBENCH_NAME + '}\n\n' + format_dashes(30) + '\n';
'\n==> GET: ' + amp_url + '\n\n' + '{"User-Agent": ' +
benchlib.UA_AMPBENCH_NAME + '}\n\n' + format_dashes(30) + '\n';
// do the request
request({
uri: amp_url,
headers: {'User-Agent': benchlib.UA_AMPBENCH},
headers: { 'User-Agent': benchlib.UA_AMPBENCH },
rejectUnauthorized: false
}, function(err, res_debug, body) {
// console.log(_debug_results);
Expand All @@ -364,12 +378,12 @@ app.get('/debug_cli/', (req, res) => {
res.status(200).send(version_msg('No AMP URL parameter found.'));
} else {
_debug_results =
'\n==> GET: ' + amp_url + '\n\n' + '{"User-Agent": '
+ benchlib.UA_AMPBENCH_NAME + '}\n\n' + format_dashes(30) + '\n';
'\n==> GET: ' + amp_url + '\n\n' + '{"User-Agent": ' +
benchlib.UA_AMPBENCH_NAME + '}\n\n' + format_dashes(30) + '\n';
// do the request
request({
uri: amp_url,
headers: {'User-Agent': benchlib.UA_AMPBENCH},
headers: { 'User-Agent': benchlib.UA_AMPBENCH },
rejectUnauthorized: false
}, function(err, res_debug, body) {
// console.log(_debug_results);
Expand All @@ -393,7 +407,7 @@ app.get('/debug_curl/', (req, res) => {
// do the request
request({
uri: amp_url,
headers: {'User-Agent': benchlib.UA_CURL},
headers: { 'User-Agent': benchlib.UA_CURL },
rejectUnauthorized: false
}, function(err, res_debug, body) {
// console.log(_debug_results);
Expand All @@ -417,7 +431,7 @@ app.get('/debug_curl_cli/', (req, res) => {
// do the request
request({
uri: amp_url,
headers: {'User-Agent': benchlib.UA_CURL},
headers: { 'User-Agent': benchlib.UA_CURL },
rejectUnauthorized: false
}, function(err, res_debug, body) {
// console.log(_debug_results);
Expand Down Expand Up @@ -470,27 +484,28 @@ const make_api_amp_links = (parse_amplinks) => {
return {
canonical_url: parse_amplinks.canonical_url,
amphtml_url: parse_amplinks.amphtml_url,
amphtml_urls: parse_amplinks.amphtml_urls,
amp_uses_feed: parse_amplinks.amp_uses_feed
};
};

const make_api_sd_validation = (api_validate_sd_return) => {
return {
status: api_validate_sd_return.status,
result: api_validate_sd_return.result,
sd_json_error: api_validate_sd_return.json_error,
sd_kind: api_validate_sd_return.kind,
sd_type: api_validate_sd_return.type,
sd_type_is_amp: api_validate_sd_return.type_is_amp,
sd_context: api_validate_sd_return.context,
sd_headline: api_validate_sd_return.news_headline,
sd_author_name: api_validate_sd_return.author_name,
sd_publisher_name: api_validate_sd_return.publisher_name,
sd_date_published: api_validate_sd_return.date_published,
sd_date_modified: api_validate_sd_return.date_modified,
sd_logo_image: api_validate_sd_return.image,
sd_article_image: api_validate_sd_return.article_image,
sd_article: api_validate_sd_return.article
status: api_validate_sd_return.status,
result: api_validate_sd_return.result,
sd_json_error: api_validate_sd_return.json_error,
sd_kind: api_validate_sd_return.kind,
sd_type: api_validate_sd_return.type,
sd_type_is_amp: api_validate_sd_return.type_is_amp,
sd_context: api_validate_sd_return.context,
sd_headline: api_validate_sd_return.news_headline,
sd_author_name: api_validate_sd_return.author_name,
sd_publisher_name: api_validate_sd_return.publisher_name,
sd_date_published: api_validate_sd_return.date_published,
sd_date_modified: api_validate_sd_return.date_modified,
sd_logo_image: api_validate_sd_return.image,
sd_article_image: api_validate_sd_return.article_image,
sd_article: api_validate_sd_return.article
};
};

Expand Down Expand Up @@ -616,21 +631,22 @@ app.get('/api2/', (req, res) => {
api_validate_amp_warnings_return = null;

let parse_amplinks = {}; // <== function parse_page_content(http_response):
// canonical_url: '',
// amphtml_url: '',
// check_robots_meta_results: 'Page content could not be read.',
// check_robots_meta_status: CHECK_FAIL,
// check_x_robots_tag_header_results: 'Response header could not be read.',
// check_x_robots_tag_header_status: CHECK_FAIL
// canonical_url: '',
// amphtml_url: '',
// amphtml_urls: '',
// check_robots_meta_results: 'Page content could not be read.',
// check_robots_meta_status: CHECK_FAIL,
// check_x_robots_tag_header_results: 'Response header could not be read.',
// check_x_robots_tag_header_status: CHECK_FAIL

let check_amplinks = {}; // <== function review_amp_links(parse_amplinks...
// check_extra: '',
// check_amp_links_canonical_url: '',
// check_amp_links_canonical_status: CHECK_NONE,
// check_amp_links_canonical_results: '',
// check_amp_links_amphtml_url: '',
// check_amp_links_amphtml_status: CHECK_NONE,
// check_amp_links_amphtml_results: ''
// check_extra: '',
// check_amp_links_canonical_url: '',
// check_amp_links_canonical_status: CHECK_NONE,
// check_amp_links_canonical_results: '',
// check_amp_links_amphtml_url: '',
// check_amp_links_amphtml_status: CHECK_NONE,
// check_amp_links_amphtml_results: ''

let check_robots_txt_return = null,
check_google_amp_cache_return = null;
Expand Down Expand Up @@ -737,8 +753,9 @@ class HttpServer {
}

var __server = null;
function init_server(server) { // called from main startup
if (null === __server) { // only once

function init_server(server) { // called from main startup
if (null === __server) { // only once
__server = new HttpServer(server);
}
return __server;
Expand All @@ -752,4 +769,4 @@ exports.init_server = init_server;
exports.version_msg = version_msg;
exports.app = app;

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Loading