Skip to content

Commit 057e633

Browse files
author
Samson
committed
build changes coming
1 parent 1273dff commit 057e633

8 files changed

Lines changed: 121 additions & 80 deletions

File tree

build/build.js

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ var cloudfront_production = 'https://d50sg51l36z7c.cloudfront.net';
1212
var cloudfront_stage = 'https://d51ivijxlr7mx.cloudfront.net';
1313
var cloudfront_vagrant = 'https://vagrant-client.apiengine.io:40443';
1414

15+
var server_production = 'https://x.apiengine.io';
16+
var server_staging = 'https://s.apiengine.io';
17+
1518
// Logging helpers
1619

1720
var types = {
@@ -41,8 +44,33 @@ program
4144

4245
log('Api Engine Client Builder', types.heading)
4346

47+
var server = null;
48+
var cloudfront = null;
49+
50+
if(program.environment === 'stage') {
51+
cloudfront = cloudfront_stage;
52+
log('Staging enviroment selected', types.label)
53+
server = server_staging;
54+
55+
} else if (program.environment === 'production' ) {
56+
log('Production enviroment selected', types.label)
57+
cloudfront = cloudfront_production;
58+
server = server_production;
59+
60+
} else if(program.environment === 'vagrant') {
61+
var cloudfront = cloudfront_vagrant;
62+
server = server_staging;
63+
log('Vagrant enviroment selected', types.label)
64+
65+
} else {
66+
server = server_staging;
67+
log('Development enviroment selected', types.label)
68+
}
69+
70+
if(program.server) {
71+
server = program.server;
72+
}
4473

45-
var cloudfront = null
4674
if(program.environment === 'stage') {
4775
cloudfront = cloudfront_stage;
4876
log('Staging enviroment selected', types.label)
@@ -128,9 +156,7 @@ if(cloudfront) {
128156

129157
}
130158

131-
if(program.server) {
132-
index = index.replace('</head>', '<meta name="server" data-server-url="'+program.server+'" /></head>')
133-
}
159+
index = index.replace('<meta data-server-url="https://s.apiengine.io" />', '<meta data-server-url="'+server+'" />')
134160

135161

136162
log('Optimization css with require.js', types.action)

index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
<meta charset="utf-8">
55
<title>API Engine - Great apps start with great apis</title>
66
<meta name="fragment" content="!">
7+
<meta data-server-url="https://s.apiengine.io" />
78
<base href="/repos/apiengine-client/" />
89
<link rel="stylesheet" href="css/styles.css">
910
<script>

js/extensions.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,21 @@ define(['jquery'], function ($) {
1010
+ pad(this.getUTCSeconds()) + 'Z';
1111
};
1212
}
13-
13+
$.fn.serializeObject = function() {
14+
var o = {};
15+
var a = this.serializeArray();
16+
$.each(a, function() {
17+
if (o[this.name] !== undefined) {
18+
if (!o[this.name].push) {
19+
o[this.name] = [o[this.name]];
20+
}
21+
o[this.name].push(this.value || '');
22+
} else {
23+
o[this.name] = this.value || '';
24+
}
25+
});
26+
return o;
27+
};
1428
(function($) {
1529
var supportedCSS,styles=document.getElementsByTagName("head")[0].style,toCheck="transformProperty WebkitTransform OTransform msTransform MozTransform".split(" ");
1630
for (var a=0;a<toCheck.length;a++) if (styles[toCheck[a]] !== undefined) supportedCSS = toCheck[a];

js/libs/backbone/backbone.cache.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
define([
2+
'backbone'
3+
], function (Backbone) {
4+
5+
return Backbone;
6+
});

js/main.js

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -37,23 +37,14 @@ require.config({
3737
// Actually kick off the application
3838

3939
require([
40+
'setup/setup'
4041
'views/app',
4142
'vm',
4243
'router',
43-
'clicky',
44-
'libs/proxino/proxino'
45-
], function(AppView, Vm, Router, norefclicky, norefProxino){
46-
47-
48-
try{ clicky.init(66633495); }catch(e){}
49-
50-
Proxino.key = "QI-BctdhtytsUUJERc5HfA";
51-
Proxino.track_errors();
52-
44+
], function(Setup, AppView, Vm, Router){
45+
Setup.setup();
5346
var appView = Vm.create({}, 'AppView', AppView);
54-
5547
Router.initialize({appView : appView});
5648
appView.render(); // render() calls Backbone.history when its ready to start
57-
5849
});
5950

js/setup/logging.js

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
define([
2+
'jquery',
3+
'libs/events/event_bus',
4+
'libs/events/events',
5+
'libs/proxino/proxino',
6+
'clicky'
7+
], function ($, EventBus, Events, norefProxino, noclickyref){
8+
9+
// Clicky Tracking
10+
try{ clicky.init(66633495); }catch(e){}
11+
12+
// Google analytics
13+
EventBus.on('all', function (event) {
14+
ga('send', {
15+
hitType: 'event',
16+
eventCategory: 'app',
17+
eventAction: event
18+
})
19+
});
20+
21+
// Proxino Error tracking
22+
Proxino.key = "QI-BctdhtytsUUJERc5HfA";
23+
Proxino.track_errors();
24+
25+
// Server Error Failures
26+
27+
$("body").ajaxError(function(ev, res, req) {
28+
if(res.status >= 500 && res.status <= 600) {
29+
var responseJSON = xhr.responseText;
30+
try {
31+
responseJSON = JSON.parse(xhr.responseText);
32+
} catch (e) {}
33+
34+
var error = new ErrorModel();
35+
error.save({
36+
"page": window.location.href,
37+
"context": req.type + ' ' + req.url,
38+
"code": res.status,
39+
"error": "Internal API error",
40+
"payload": {
41+
sent : req.data,
42+
received : responseJSON
43+
}
44+
}, {});
45+
}
46+
});
47+
48+
})

js/setup/setup.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
define([
2+
'setup/logging'
3+
], function (Logging){
4+
Logging.setup();
5+
6+
7+
});

js/views/app.js

Lines changed: 11 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -19,75 +19,23 @@ define([
1919
var AppView = Backbone.View.extend({
2020
el: 'body',
2121
initialize: function () {
22-
// log all 500 error codes with the server. We may also log others - this is done in libs/form/form.js
23-
// when no UI elements are found for handling a valid server error condition.
24-
EventBus.on('all', function (event) {
25-
console.log('gaaa');
26-
ga('send', {
27-
hitType: 'event',
28-
eventCategory: 'app',
29-
eventAction: event
30-
})
31-
});
32-
EventBus.trigger(Events.NEW_USER);
33-
$("body").ajaxError(function(ev, res, req) {
34-
if(res.status >= 500 && res.status <= 600) {
35-
var responseJSON = xhr.responseText;
36-
try {
37-
responseJSON = JSON.parse(xhr.responseText);
38-
} catch (e) {}
39-
40-
var error = new ErrorModel();
41-
error.save({
42-
"page": window.location.href,
43-
"context": req.type + ' ' + req.url,
44-
"code": res.status,
45-
"error": "Internal API error",
46-
"payload": {
47-
sent : req.data,
48-
received : responseJSON
49-
}
50-
}, {});
51-
}
52-
console.log(arguments);
53-
});
54-
55-
// This snipper should usually be loaded elsewhere
56-
// It simply takes a <form> and converts its values to an object
57-
$.fn.serializeObject = function() {
58-
var o = {};
59-
var a = this.serializeArray();
60-
$.each(a, function() {
61-
if (o[this.name] !== undefined) {
62-
if (!o[this.name].push) {
63-
o[this.name] = [o[this.name]];
64-
}
65-
o[this.name].push(this.value || '');
66-
} else {
67-
o[this.name] = this.value || '';
68-
}
69-
});
70-
return o;
71-
};
22+
7223

7324
var that = this;
7425

75-
$.ajaxPrefilter( function( options, originalOptions, jqXHR ) {
76-
// Your server goes below
77-
if(options.url.indexOf('proxino') === -1) {
78-
if($('[data-server-url]').length > 0) {
79-
options.url = $('[data-server-url]').attr('data-server-url');
80-
} else if (window.location.host === 'apiengine.io') {
81-
options.url = 'https://x.apiengine.io' + options.url;
26+
$.ajaxPrefilter( function( options, originalOptions, jqXHR ) {
27+
// Move these server url declarations all to custom url data attribute
28+
if(options.url.indexOf('proxino') === -1) {
29+
if($('[data-server-url]').length > 0) {
30+
options.url = $('[data-server-url]').attr('data-server-url');
31+
} else if (window.location.host === 'apiengine.io') {
32+
options.url = 'https://x.apiengine.io' + options.url;
8233

83-
} else {
84-
options.url = 'https://s.apiengine.io' + options.url;
34+
} else {
35+
options.url = 'https://s.apiengine.io' + options.url;
36+
}
8537
}
86-
//options.url = 'http://192.168.2.111:3000' + options.url;
87-
}// else {
88-
//options.url = 'http://d3gscmgl75g1oq.cloudfront.net' + options.url;
8938

90-
// };
9139
});
9240

9341
},

0 commit comments

Comments
 (0)