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,13 +1,14 @@
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 () {
return this.each(function() {
$(this).bind('enterPress', fn);
$(this).keyup(function (e) {
$(this).keyup(function(e) {
if (e.keyCode === 13) {
$(this).trigger('enterPress');
}
@ -15,22 +16,21 @@ $.fn.pressEnter = function (fn) {
});
};
var Keeper = (function () {
var Keeper = function() {
var self = this;
console.log('GO!');
var $list = $('#listContainer');
var displayList = function (obj) {
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 () {
$('#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);
@ -58,52 +56,44 @@ var Keeper = (function () {
$bodyContents.append(html);
$('#redo').on('click', function () {
$('#redo').on('click', function() {
self.trigger('redo', redoData);
});
$('#tagSave').on('click', function () {
$('#tagSave').on('click', function() {
self.trigger('tagsave', redoData);
});
$('#tageditmode').on('click', function () {
$('#tageditmode').on('click', function() {
self.trigger('startTags');
});
}
}, getBookmark = function (id) {
//console.log('getBookmark');
}, 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,
//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);
@ -112,81 +102,66 @@ var Keeper = (function () {
},
getMainTagList = function () {
getMainTagList = 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()
.split(/\s*,\s*/)
.map(function (col) {
.map(function(col) {
return col.trim();
})
.filter(function (col) {
.filter(function(col) {
return col && col.length;
});
}
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,145 +169,112 @@ 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) {
}
});
};
$('#newurl').pressEnter(function () {
$('#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 () {
/* SetTimeout(function () {
getList();
}, 5000);*/
}
});
$('#fnRefresh').on('click', function () {
$('#fnRefresh').on('click', function() {
getList();
});
@ -341,35 +283,31 @@ var Keeper = (function () {
self.trigger('hashchange', location.hash);
});
this.bind('redo', function (data) {
this.bind('redo', function(data) {
redo(data);
});
this.bind('tagsave', function (data) {
this.bind('tagsave', function(data) {
saveTags(data);
});
this.bind('startTags', function (data) {
this.bind('startTags', function(data) {
$('#visualTabs').toggle();
$('#tagForm').toggle();
});
this.bind('hashchange', function (data) {
this.bind('hashchange', function(data) {
var tagroute = data.replace('#?', '');
if (tagroute !== '')
{
if (tagroute !== '') {
listFromTag(tagroute);
}
else
{
} else {
getList();
}
});
start();
})
;
};
MicroEvent.mixin(Keeper);

View File

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

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;