headers for request

This commit is contained in:
Martin Donnelly 2016-03-23 10:29:00 +00:00
parent e5334cc5e7
commit d85d7fddd7
5 changed files with 335 additions and 308 deletions

32
.editorconfig Normal file
View File

@ -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

46
.jscsrc Normal file
View File

@ -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": "'"
}

View File

@ -1,3 +1,4 @@
import * as EJS from 'ejs';
'use strict';
/**
* Created by Martin on 24/02/2016.
@ -15,7 +16,7 @@ $.fn.pressEnter = function (fn) {
});
};
var Keeper = (function () {
var Keeper = function() {
var self = this;
@ -23,14 +24,13 @@ var Keeper = (function () {
var $list = $('#listContainer');
var displayList = function(obj) {
var html = new EJS({url: '/partials/list.ejs'}).render(obj);
// console.log(html);
// Console.log(html);
$list.empty();
$list.append(html);
$('#listContainer').find('.entry').not('.emptyMessage').click(function() {
getBookmark(this.id);
});
},
displayPage = function (obj) {
}, displayPage = function(obj) {
var $bodyContents = $('#bodyContents');
if (obj.reduced.length > 0) {
@ -46,9 +46,7 @@ var Keeper = (function () {
};
var redoData = {
_id: obj._id,
_rev: obj._rev,
url: obj.url
_id: obj._id, _rev: obj._rev, url: obj.url
};
var html = new EJS({url: 'partials/view.ejs'}).render(vdata);
@ -74,36 +72,28 @@ var Keeper = (function () {
}
}, getBookmark = function(id) {
//console.log('getBookmark');
// 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,
//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'
},
success: function (data) {
// console.log(data);
}, success: function(data) {
// Console.log(data);
displayPage(data);
},
error: function (xhr, type) {
console.log('ajax error');
console.log(xhr);
console.log(type);
}, error: function(xhr, type) {
}
});
},
updateMainTagList = function (obj) {
}, updateMainTagList = function(obj) {
var $taglist = $('#tagList');
var html = new EJS({url: '/partials/taglist.ejs'}).render(obj);
@ -116,62 +106,46 @@ var Keeper = (function () {
var url = '/tags';
$.ajax({
type: 'GET',
url: url,
data: '',
dataType: 'json',
type: 'GET', url: url, data: '', 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'
},
success: function (data) {
// console.log(data);
}, success: function(data) {
// Console.log(data);
updateMainTagList(data);
},
error: function (xhr, type) {
console.log('ajax error');
console.log(xhr);
console.log(type);
}, error: function(xhr, type) {
}
});
},
getList = function () {
}, getList = function() {
var url = '/list';
$.ajax({
type: 'GET',
url: url,
data: '',
dataType: 'json',
type: 'GET', url: url, data: '', 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'
},
success: function (data) {
// console.log(data);
}, success: function(data) {
// Console.log(data);
displayList(data);
},
error: function (xhr, type) {
console.log('ajax error');
console.log(xhr);
console.log(type);
}, error: function(xhr, type) {
}
});
},
saveTags = function (d) {
}, saveTags = function(d) {
function parse(input) {
return input
.trim()
@ -186,7 +160,8 @@ var Keeper = (function () {
var data = d;
var url = '/tags';
var tags = {}, tagItems = $('#edittags').val();
var tags = {};
var tagItems = $('#edittags').val();
tagItems = parse(tagItems);
tags.list = tagItems;
tags.solid = tagItems.join(', ');
@ -194,126 +169,93 @@ var Keeper = (function () {
data.tags = tags;
$.ajax({
type: 'POST',
url: url,
data: d,
dataType: 'json',
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'
},
success: function () {
// console.log(data);
}, 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);
}, error: function(xhr, type) {
}
});
}
, addNew = function (newUrl) {
}, addNew = function(newUrl) {
var url = '/add';
var data = {url: JSON.stringify(newUrl)};
$.ajax({
type: 'POST',
url: url,
data: data,
dataType: 'json',
type: 'POST', url: url, data: data, 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'
},
success: function () {
// console.log(data);
}, success: function() {
// Console.log(data);
// displayList(data);
},
error: function (xhr, type) {
console.log('ajax error');
console.log(xhr);
console.log(type);
}, error: function(xhr, type) {
}
});
},
redo = function (d) {
}, redo = function(d) {
console.log('redooing');
var url = '/redo';
$.ajax({
type: 'POST',
url: url,
data: d,
dataType: 'json',
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'
},
success: function () {
// console.log(data);
}, success: function() {
// Console.log(data);
// displayList(data);
},
error: function (xhr, type) {
console.log('ajax error');
console.log(xhr);
console.log(type);
}, error: function(xhr, type) {
}
});
},
start = function () {
}, start = function() {
getList();
getMainTagList();
},
listFromTag = function (tag) {
}, listFromTag = function(tag) {
console.log('get for ' + tag);
var url = '/tags/' + tag;
$.ajax({
type: 'GET',
url: url,
data: '',
dataType: 'json',
type: 'GET', url: url, data: '', 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'
},
success: function (data) {
// console.log(data);
}, success: function(data) {
// Console.log(data);
displayList(data);
},
error: function (xhr, type) {
console.log('ajax error');
console.log(xhr);
console.log(type);
}, error: function(xhr, type) {
}
});
@ -326,7 +268,7 @@ var Keeper = (function () {
addNew(url);
$('#addstatus').fadeIn(400).delay(1500).fadeOut(400);
$(this).val('');
/* setTimeout(function () {
/* SetTimeout(function () {
getList();
}, 5000);*/
}
@ -357,19 +299,15 @@ var Keeper = (function () {
var tagroute = data.replace('#?', '');
if (tagroute !== '')
{
if (tagroute !== '') {
listFromTag(tagroute);
}
else
{
} else {
getList();
}
});
start();
})
;
};
MicroEvent.mixin(Keeper);

View File

@ -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",

View File

@ -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;