From d85d7fddd7b1d13f70fa55bdfe60525bd33b0ae7 Mon Sep 17 00:00:00 2001 From: Martin Donnelly Date: Wed, 23 Mar 2016 10:29:00 +0000 Subject: [PATCH] headers for request --- .editorconfig | 32 +++ .jscsrc | 46 ++++ app/js/app.js | 548 +++++++++++++++++++++-------------------------- package.json | 4 +- server/keeper.js | 13 +- 5 files changed, 335 insertions(+), 308 deletions(-) create mode 100644 .editorconfig create mode 100644 .jscsrc diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..e86f5fa --- /dev/null +++ b/.editorconfig @@ -0,0 +1,32 @@ +; http://editorconfig.org + +root = true + +[*] +charset = utf-8 +end_of_line = lf +insert_final_newline = true +trim_trailing_whitespace = true +indent_style = space +indent_size = 2 + +[*.txt] +insert_final_newline = false +trim_trailing_whitespace = false + +[*.py] +indent_size = 4 + +[*.m] +indent_size = 4 + +[Makefile] +indent_style = tab +indent_size = 8 + +[*.{js,json}] +indent_style = space +indent_size = 2 + +[*.md] +trim_trailing_whitespace = false diff --git a/.jscsrc b/.jscsrc new file mode 100644 index 0000000..3b76c52 --- /dev/null +++ b/.jscsrc @@ -0,0 +1,46 @@ +{ + "disallowKeywords": ["with"], + "disallowKeywordsOnNewLine": ["else"], + "disallowMixedSpacesAndTabs": true, + "disallowMultipleVarDecl": "exceptUndefined", + "disallowNewlineBeforeBlockStatements": true, + "disallowQuotedKeysInObjects": true, + "disallowSpaceAfterObjectKeys": true, + "disallowSpaceAfterPrefixUnaryOperators": true, + "disallowSpacesInFunction": { + "beforeOpeningRoundBrace": true + }, + "disallowSpacesInsideParentheses": true, + "disallowTrailingWhitespace": true, + "maximumLineLength": 120, + "requireCamelCaseOrUpperCaseIdentifiers": false, + "requireCapitalizedComments": true, + "requireCapitalizedConstructors": true, + "requireCurlyBraces": true, + "requireSpaceAfterKeywords": [ + "if", + "else", + "for", + "while", + "do", + "switch", + "case", + "return", + "try", + "catch", + "typeof" + ], + "requireSpaceAfterLineComment": true, + "requireSpaceAfterBinaryOperators": true, + "requireSpaceBeforeBinaryOperators": true, + "requireSpaceBeforeBlockStatements": true, + "requireSpaceBeforeObjectValues": true, + "requireSpacesInFunction": { + "beforeOpeningCurlyBrace": true + }, + "requireTrailingComma": false, + "requireEarlyReturn": false, + "validateIndentation": 2, + "validateLineBreaks": "LF", + "validateQuoteMarks": "'" +} diff --git a/app/js/app.js b/app/js/app.js index 41b133b..b241ff8 100644 --- a/app/js/app.js +++ b/app/js/app.js @@ -1,375 +1,313 @@ +import * as EJS from 'ejs'; 'use strict'; /** * Created by Martin on 24/02/2016. */ -$.fn.pressEnter = function (fn) { +$.fn.pressEnter = function(fn) { - return this.each(function () { - $(this).bind('enterPress', fn); - $(this).keyup(function (e) { - if (e.keyCode === 13) { - $(this).trigger('enterPress'); - } - }); + return this.each(function() { + $(this).bind('enterPress', fn); + $(this).keyup(function(e) { + if (e.keyCode === 13) { + $(this).trigger('enterPress'); + } }); + }); }; -var Keeper = (function () { +var Keeper = function() { - var self = this; + var self = this; - console.log('GO!'); - var $list = $('#listContainer'); - var displayList = function (obj) { - var html = new EJS({url: '/partials/list.ejs'}).render(obj); - // console.log(html); - $list.empty(); - $list.append(html); - $('#listContainer').find('.entry').not('.emptyMessage').click(function () { - getBookmark(this.id); - }); - }, - displayPage = function (obj) { - var $bodyContents = $('#bodyContents'); - - if (obj.reduced.length > 0) { - var vdata = { - data: { - _id: obj._id, - _rev: obj._rev, - title: obj.title, - reduced: obj.reduced, - tags: obj.tags, - url: obj.url - } - }; - - var redoData = { - _id: obj._id, - _rev: obj._rev, - url: obj.url - }; - - var html = new EJS({url: 'partials/view.ejs'}).render(vdata); - - $bodyContents.empty(); - $bodyContents.scrollTop(0); - - $bodyContents.append(html); - - $('#redo').on('click', function () { - self.trigger('redo', redoData); - - }); - - $('#tagSave').on('click', function () { - self.trigger('tagsave', redoData); - - }); - - $('#tageditmode').on('click', function () { - self.trigger('startTags'); - }); + console.log('GO!'); + var $list = $('#listContainer'); + var displayList = function(obj) { + var html = new EJS({url: '/partials/list.ejs'}).render(obj); + // Console.log(html); + $list.empty(); + $list.append(html); + $('#listContainer').find('.entry').not('.emptyMessage').click(function() { + getBookmark(this.id); + }); + }, displayPage = function(obj) { + var $bodyContents = $('#bodyContents'); + if (obj.reduced.length > 0) { + var vdata = { + data: { + _id: obj._id, + _rev: obj._rev, + title: obj.title, + reduced: obj.reduced, + tags: obj.tags, + url: obj.url } - }, getBookmark = function (id) { - //console.log('getBookmark'); + }; + + var redoData = { + _id: obj._id, _rev: obj._rev, url: obj.url + }; + + var html = new EJS({url: 'partials/view.ejs'}).render(vdata); + + $bodyContents.empty(); + $bodyContents.scrollTop(0); + + $bodyContents.append(html); + + $('#redo').on('click', function() { + self.trigger('redo', redoData); + + }); + + $('#tagSave').on('click', function() { + self.trigger('tagsave', redoData); + + }); + + $('#tageditmode').on('click', function() { + self.trigger('startTags'); + }); + + } + }, getBookmark = function(id) { + // Console.log('getBookmark'); var url = '/entry/' + id; var data = ''; $.ajax({ - type: 'GET', - url: url, - data: data, - dataType: 'json', + type: 'GET', url: url, data: data, dataType: 'json', - timeout: 10000, + timeout: 10000, - //contentType: ('application/json'), - headers: { - 'Access-Control-Allow-Origin': '*', - 'Access-Control-Allow-Methods': 'PUT, GET, POST, DELETE, OPTIONS', - 'Access-Control-Allow-Headers': 'Content-Type' + // ContentType: ('application/json'), + headers: { + 'Access-Control-Allow-Origin': '*', + 'Access-Control-Allow-Methods': 'PUT, GET, POST, DELETE, OPTIONS', + 'Access-Control-Allow-Headers': 'Content-Type' - }, - success: function (data) { - // console.log(data); - displayPage(data); - }, - error: function (xhr, type) { - console.log('ajax error'); - console.log(xhr); - console.log(type); - } + }, success: function(data) { + // Console.log(data); + displayPage(data); + }, error: function(xhr, type) { + + } }); - }, - updateMainTagList = function (obj) { - var $taglist = $('#tagList'); + }, updateMainTagList = function(obj) { + var $taglist = $('#tagList'); - var html = new EJS({url: '/partials/taglist.ejs'}).render(obj); - $taglist.empty(); - $taglist.html(html); + var html = new EJS({url: '/partials/taglist.ejs'}).render(obj); + $taglist.empty(); + $taglist.html(html); - }, + }, - getMainTagList = function () { - var url = '/tags'; + getMainTagList = function() { + var url = '/tags'; - $.ajax({ - type: 'GET', - url: url, - data: '', - dataType: 'json', + $.ajax({ + type: 'GET', url: url, data: '', dataType: 'json', - timeout: 10000, + timeout: 10000, - //contentType: ('application/json'), - headers: { - 'Access-Control-Allow-Origin': '*', - 'Access-Control-Allow-Methods': 'PUT, GET, POST, DELETE, OPTIONS', - 'Access-Control-Allow-Headers': 'Content-Type' + // ContentType: ('application/json'), + headers: { + 'Access-Control-Allow-Origin': '*', + 'Access-Control-Allow-Methods': 'PUT, GET, POST, DELETE, OPTIONS', + 'Access-Control-Allow-Headers': 'Content-Type' - }, - success: function (data) { - // console.log(data); - updateMainTagList(data); - }, - error: function (xhr, type) { - console.log('ajax error'); - console.log(xhr); - console.log(type); - } - }); - }, - getList = function () { + }, success: function(data) { + // Console.log(data); + updateMainTagList(data); + }, error: function(xhr, type) { - var url = '/list'; + } + }); + }, getList = function() { - $.ajax({ - type: 'GET', - url: url, - data: '', - dataType: 'json', + var url = '/list'; - timeout: 10000, + $.ajax({ + type: 'GET', url: url, data: '', dataType: 'json', - //contentType: ('application/json'), - headers: { - 'Access-Control-Allow-Origin': '*', - 'Access-Control-Allow-Methods': 'PUT, GET, POST, DELETE, OPTIONS', - 'Access-Control-Allow-Headers': 'Content-Type' + timeout: 10000, + + // ContentType: ('application/json'), + headers: { + 'Access-Control-Allow-Origin': '*', + 'Access-Control-Allow-Methods': 'PUT, GET, POST, DELETE, OPTIONS', + 'Access-Control-Allow-Headers': 'Content-Type' + + }, success: function(data) { + // Console.log(data); + displayList(data); + }, error: function(xhr, type) { - }, - success: function (data) { - // console.log(data); - displayList(data); - }, - error: function (xhr, type) { - console.log('ajax error'); - console.log(xhr); - console.log(type); - } - }); - }, - saveTags = function (d) { - function parse(input) { - return input - .trim() - .split(/\s*,\s*/) - .map(function (col) { - return col.trim(); - }) - .filter(function (col) { - return col && col.length; - }); } + }); + }, saveTags = function(d) { + function parse(input) { + return input + .trim() + .split(/\s*,\s*/) + .map(function(col) { + return col.trim(); + }) + .filter(function(col) { + return col && col.length; + }); + } - var data = d; - var url = '/tags'; - var tags = {}, tagItems = $('#edittags').val(); - tagItems = parse(tagItems); - tags.list = tagItems; - tags.solid = tagItems.join(', '); + var data = d; + var url = '/tags'; + var tags = {}; + var tagItems = $('#edittags').val(); + tagItems = parse(tagItems); + tags.list = tagItems; + tags.solid = tagItems.join(', '); - data.tags = tags; + data.tags = tags; - $.ajax({ - type: 'POST', - url: url, - data: d, - dataType: 'json', + $.ajax({ + type: 'POST', url: url, data: d, dataType: 'json', timeout: 10000, - //contentType: ('application/json'), + // ContentType: ('application/json'), headers: { - 'Access-Control-Allow-Origin': '*', - 'Access-Control-Allow-Methods': 'PUT, GET, POST, DELETE, OPTIONS', - 'Access-Control-Allow-Headers': 'Content-Type' + 'Access-Control-Allow-Origin': '*', + 'Access-Control-Allow-Methods': 'PUT, GET, POST, DELETE, OPTIONS', + 'Access-Control-Allow-Headers': 'Content-Type' + + }, success: function() { + // Console.log(data); + // displayList(data); + $('#visualTabs').toggle(); + $('#tagForm').toggle(); + }, error: function(xhr, type) { - }, - success: function () { - // console.log(data); - // displayList(data); - $('#visualTabs').toggle(); - $('#tagForm').toggle(); - }, - error: function (xhr, type) { - console.log('ajax error'); - console.log(xhr); - console.log(type); } - }); - } + }); + }, addNew = function(newUrl) { + var url = '/add'; - , addNew = function (newUrl) { - var url = '/add'; + var data = {url: JSON.stringify(newUrl)}; + $.ajax({ + type: 'POST', url: url, data: data, dataType: 'json', - var data = {url: JSON.stringify(newUrl)}; - $.ajax({ - type: 'POST', - url: url, - data: data, - dataType: 'json', + timeout: 10000, - timeout: 10000, + //ContentType: ('application/json'), + headers: { + 'Access-Control-Allow-Origin': '*', + 'Access-Control-Allow-Methods': 'PUT, GET, POST, DELETE, OPTIONS', + 'Access-Control-Allow-Headers': 'Content-Type' - //contentType: ('application/json'), - headers: { - 'Access-Control-Allow-Origin': '*', - 'Access-Control-Allow-Methods': 'PUT, GET, POST, DELETE, OPTIONS', - 'Access-Control-Allow-Headers': 'Content-Type' + }, success: function() { + // Console.log(data); + // displayList(data); + }, error: function(xhr, type) { - }, - success: function () { - // console.log(data); - // displayList(data); - }, - error: function (xhr, type) { - console.log('ajax error'); - console.log(xhr); - console.log(type); - } - }); - }, - redo = function (d) { - console.log('redooing'); - var url = '/redo'; + } + }); + }, redo = function(d) { + console.log('redooing'); + var url = '/redo'; - $.ajax({ - type: 'POST', - url: url, - data: d, - dataType: 'json', + $.ajax({ + type: 'POST', url: url, data: d, dataType: 'json', - timeout: 10000, + timeout: 10000, - //contentType: ('application/json'), - headers: { - 'Access-Control-Allow-Origin': '*', - 'Access-Control-Allow-Methods': 'PUT, GET, POST, DELETE, OPTIONS', - 'Access-Control-Allow-Headers': 'Content-Type' + //ContentType: ('application/json'), + headers: { + 'Access-Control-Allow-Origin': '*', + 'Access-Control-Allow-Methods': 'PUT, GET, POST, DELETE, OPTIONS', + 'Access-Control-Allow-Headers': 'Content-Type' - }, - success: function () { - // console.log(data); - // displayList(data); - }, - error: function (xhr, type) { - console.log('ajax error'); - console.log(xhr); - console.log(type); - } - }); - }, - start = function () { + }, success: function() { + // Console.log(data); + // displayList(data); + }, error: function(xhr, type) { - getList(); - getMainTagList(); - }, - listFromTag = function (tag) { - console.log('get for ' + tag); - var url = '/tags/' + tag; + } + }); + }, start = function() { - $.ajax({ - type: 'GET', - url: url, - data: '', - dataType: 'json', + getList(); + getMainTagList(); + }, listFromTag = function(tag) { + console.log('get for ' + tag); + var url = '/tags/' + tag; - timeout: 10000, + $.ajax({ + type: 'GET', url: url, data: '', dataType: 'json', - //contentType: ('application/json'), - headers: { - 'Access-Control-Allow-Origin': '*', - 'Access-Control-Allow-Methods': 'PUT, GET, POST, DELETE, OPTIONS', - 'Access-Control-Allow-Headers': 'Content-Type' + timeout: 10000, - }, - success: function (data) { - // console.log(data); - displayList(data); - }, - error: function (xhr, type) { - console.log('ajax error'); - console.log(xhr); - console.log(type); - } - }); + // ContentType: ('application/json'), + headers: { + 'Access-Control-Allow-Origin': '*', + 'Access-Control-Allow-Methods': 'PUT, GET, POST, DELETE, OPTIONS', + 'Access-Control-Allow-Headers': 'Content-Type' - }; + }, success: function(data) { + // Console.log(data); + displayList(data); + }, error: function(xhr, type) { - $('#newurl').pressEnter(function () { - var url = $(this).val(); - if (url !== null) { - console.log('Adding: ' + url); - addNew(url); - $('#addstatus').fadeIn(400).delay(1500).fadeOut(400); - $(this).val(''); - /* setTimeout(function () { - getList(); - }, 5000);*/ - } - }); + } + }); - $('#fnRefresh').on('click', function () { - getList(); - }); + }; - $(window).on('hashchange', ()=> { + $('#newurl').pressEnter(function() { + var url = $(this).val(); + if (url !== null) { + console.log('Adding: ' + url); + addNew(url); + $('#addstatus').fadeIn(400).delay(1500).fadeOut(400); + $(this).val(''); + /* SetTimeout(function () { + getList(); + }, 5000);*/ + } + }); - self.trigger('hashchange', location.hash); - }); + $('#fnRefresh').on('click', function() { + getList(); + }); - this.bind('redo', function (data) { - redo(data); - }); + $(window).on('hashchange', ()=> { - this.bind('tagsave', function (data) { - saveTags(data); - }); - this.bind('startTags', function (data) { - $('#visualTabs').toggle(); - $('#tagForm').toggle(); - }); + self.trigger('hashchange', location.hash); + }); - this.bind('hashchange', function (data) { + this.bind('redo', function(data) { + redo(data); + }); - var tagroute = data.replace('#?', ''); + this.bind('tagsave', function(data) { + saveTags(data); + }); + this.bind('startTags', function(data) { + $('#visualTabs').toggle(); + $('#tagForm').toggle(); + }); - if (tagroute !== '') - { - listFromTag(tagroute); - } - else - { - getList(); - } - }); + this.bind('hashchange', function(data) { - start(); - }) - ; + var tagroute = data.replace('#?', ''); + + if (tagroute !== '') { + listFromTag(tagroute); + } else { + getList(); + } + }); + + start(); +}; MicroEvent.mixin(Keeper); diff --git a/package.json b/package.json index bc670a5..479ba1e 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,7 @@ "main": "recipe-server.js", "scripts": { "test": "echo \"Error: no test specified\" && exit 1", - "update" :"git pull && npm install && gulp default" + "update": "git pull && npm install && gulp default" }, "author": "", "license": "ISC", @@ -31,7 +31,7 @@ "gulp-cssnano": "^2.1.1", "gulp-html-replace": "^1.5.5", "gulp-htmlmin": "^1.3.0", - "gulp-inject": "^3.0.0", + "gulp-inject": "^4.0.0", "gulp-jshint": "^2.0.0", "gulp-livereload": "^3.8.1", "gulp-notify": "^2.2.0", diff --git a/server/keeper.js b/server/keeper.js index 9832e18..8a71168 100644 --- a/server/keeper.js +++ b/server/keeper.js @@ -284,7 +284,18 @@ function genericGrab(obj, res) { logger.info(_id); logger.info(_ver); - request(url, function (err, resp, body) { + + var options = { + url: url, + headers: { + 'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.87 Safari/537.36' + }, + jar:true, + followRedirect:true, + followAllRedirects:true + }; + + request(options, function (err, resp, body) { if (err) throw err;