Skip to content

Commit 3af3abf

Browse files
committed
Added robot flag into the routing + renamed isSecure to secured + new beta version.
1 parent 3e5b442 commit 3af3abf

7 files changed

Lines changed: 90 additions & 8 deletions

File tree

changes.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,13 @@
66
- added: `U.parseTheme(path)` --> parses theme name
77
- added: `@{href}` or `@{href(obj)}` or `@{href(key, value)}` --> query string manipulation (more in documentation)
88
- added: `.jsx` content-type
9+
- added: `robot` flag into the routing (for search engines)
10+
- added: property `req.robot`
11+
- added: property `controller.robot`
12+
- added: property `controller.mobile`
913

14+
- updated: (IMPORTANT) controller.isSecure was renamed to controller.secured
15+
- updated: (IMPORTANT) req.isSecure was renamed to req.secured
1016
- updated: `F.mail()` supports themes with view nema like this `=default/someview'`
1117
- updated: `@{import()}` supports movies and images
1218
- updated: `@{import()}` can contain schema name in the path like this `=YOURSCHEMA/somefile.js`

index.js

Lines changed: 40 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ var POWEREDBY = '...';
5555
var REQUEST_COMPRESS_CONTENTTYPE = { 'text/plain': true, 'text/javascript': true, 'text/css': true, 'text/jsx': true, 'application/x-javascript': true, 'application/json': true, 'text/xml': true, 'image/svg+xml': true, 'text/x-markdown': true, 'text/html': true };
5656
var TEMPORARY_KEY_REGEX = /\//g;
5757
var REG_MOBILE = /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini|Mobile|Tablet/i;
58+
var REG_ROBOT = /search|agent|bot|crawler/i;
5859
var REG_VERSIONS = /(href|src)="[a-zA-Z0-9\/\:\-\.]+\.(jpg|js|css|png|gif|svg|html|ico|json|less|sass|scss|swf|txt|webp|woff|woff2|xls|xlsx|xml|xsl|xslt|zip|rar|csv|doc|docx|eps|gzip|jpe|jpeg|manifest|mov|mp3|mp4|ogg|package|pdf)"/gi;
5960
var REG_MULTIPART = /\/form\-data$/i;
6061
var REQUEST_PROXY_FLAGS = ['post', 'json'];
@@ -415,7 +416,7 @@ function Framework() {
415416

416417
this.id = null;
417418
this.version = 1960;
418-
this.version_header = '1.9.6-17';
419+
this.version_header = '1.9.6-18';
419420

420421
var version = process.version.toString().replace('v', '').replace(/\./g, '');
421422
if (version[0] !== '0' || version[1] !== '0')
@@ -638,7 +639,7 @@ function Framework() {
638639
this._request_check_redirect = false;
639640
this._request_check_referer = false;
640641
this._request_check_POST = false;
641-
this._request_check_mobile = false;
642+
this._request_check_robot = false;
642643
this._length_middleware = 0;
643644
this._length_request_middleware = 0;
644645
this._length_files = 0;
@@ -758,6 +759,7 @@ Framework.prototype._routesSort = function() {
758759

759760
var cache = {};
760761
var length = self.routes.web.length;
762+
var url;
761763

762764
for (var i = 0; i < length; i++) {
763765
var route = self.routes.web[i];
@@ -770,7 +772,7 @@ Framework.prototype._routesSort = function() {
770772
continue;
771773
if (route.flags.indexOf('get') === -1)
772774
continue;
773-
var url = route.url.join('/');
775+
url = route.url.join('/');
774776
cache[url] = true;
775777
}
776778

@@ -780,7 +782,7 @@ Framework.prototype._routesSort = function() {
780782
continue;
781783
if (route.flags.indexOf('get') === -1)
782784
continue;
783-
var url = route.url.join('/');
785+
url = route.url.join('/');
784786
route.isMOBILE_VARY = cache[url] === true;
785787
}
786788

@@ -1219,6 +1221,7 @@ Framework.prototype.route = function(url, funcExecute, flags, length, middleware
12191221
var isMOBILE = false;
12201222
var isJSON = false;
12211223
var isDELAY = false;
1224+
var isROBOT = false;
12221225

12231226
if (flags) {
12241227

@@ -1302,7 +1305,10 @@ Framework.prototype.route = function(url, funcExecute, flags, length, middleware
13021305
break;
13031306
case 'mobile':
13041307
isMOBILE = true;
1305-
self._request_check_mobile = true;
1308+
break;
1309+
case 'robot':
1310+
isROBOT = true;
1311+
self._request_check_robot = true;
13061312
break;
13071313
case 'authorize':
13081314
case 'authorized':
@@ -1465,6 +1471,7 @@ Framework.prototype.route = function(url, funcExecute, flags, length, middleware
14651471
isXML: flags.indexOf('xml') !== -1,
14661472
isRAW: isRaw,
14671473
isMOBILE: isMOBILE,
1474+
isROBOT: isROBOT,
14681475
isMOBILE_VARY: isMOBILE,
14691476
isGENERATOR: isGENERATOR,
14701477
isMEMBER: isMember,
@@ -6270,7 +6277,7 @@ Framework.prototype._upgrade = function(req, socket, head) {
62706277

62716278
req.session = null;
62726279
req.user = null;
6273-
req.flags = [req.isSecure ? 'https' : 'http', 'get'];
6280+
req.flags = [req.secured ? 'https' : 'http', 'get'];
62746281

62756282
var path = framework_utils.path(req.uri.pathname);
62766283
var websocket = new WebSocketClient(req, socket, head);
@@ -9895,6 +9902,10 @@ Controller.prototype = {
98959902
return this.req.isSecure;
98969903
},
98979904

9905+
get secured() {
9906+
return this.req.secured;
9907+
},
9908+
98989909
get session() {
98999910
return this.req.session;
99009911
},
@@ -9919,6 +9930,14 @@ Controller.prototype = {
99199930
framework.global = value;
99209931
},
99219932

9933+
get mobile() {
9934+
return this.req.mobile;
9935+
},
9936+
9937+
get robot() {
9938+
return this.req.robot;
9939+
},
9940+
99229941
get async() {
99239942

99249943
var self = this;
@@ -12928,6 +12947,10 @@ WebSocket.prototype = {
1292812947
return this.req.isSecure;
1292912948
},
1293012949

12950+
get secured() {
12951+
return this.req.secured;
12952+
},
12953+
1293112954
get async() {
1293212955

1293312956
var self = this;
@@ -14449,6 +14472,11 @@ http.IncomingMessage.prototype = {
1444914472
},
1445014473

1445114474
get isSecure() {
14475+
OBSOLETE('req.isSecure', 'Use req.secured');
14476+
return this.uri.protocol === 'https:' || this.uri.protocol === 'wss:';
14477+
},
14478+
14479+
get secured() {
1445214480
return this.uri.protocol === 'https:' || this.uri.protocol === 'wss:';
1445314481
},
1445414482

@@ -14464,6 +14492,12 @@ http.IncomingMessage.prototype = {
1446414492
return this.$mobile;
1446514493
},
1446614494

14495+
get robot() {
14496+
if (this.$robot === undefined)
14497+
this.$robot = REG_ROBOT.test(this.headers['user-agent']);
14498+
return this.$robot;
14499+
},
14500+
1446714501
set language(value) {
1446814502
this.$language = value;
1446914503
}

internal.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -496,6 +496,8 @@ exports.routeCompareFlags2 = function(req, route, noLoggedUnlogged) {
496496
return 0;
497497
if (route.isMOBILE && !req.mobile)
498498
return 0;
499+
if (route.isROBOT && !req.robot)
500+
return 0;
499501
var method = req.method;
500502
if (route.method) {
501503
if (route.method !== method)

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
"name": "Dusan Dragula",
6060
"email": "dusan.dragula@goodrequest.com"
6161
}],
62-
"version": "1.9.6-17",
62+
"version": "1.9.6-18",
6363
"homepage": "http://www.totaljs.com",
6464
"bugs": {
6565
"url": "https://github.com/totaljs/framework/issues",

test/controllers/default.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ exports.install = function() {
3232
flags: ['unauthorize']
3333
});
3434

35+
framework.route('/', function() {
36+
this.plain('ROBOT');
37+
}, ['robot']);
38+
3539
framework.route('/view-in-modules/', '.' + F.path.modules('someview'));
3640
framework.route('/options/', plain_options, ['options']);
3741
framework.route('/exception/', 'exception');
@@ -453,7 +457,7 @@ function viewIndex() {
453457
assert.ok(framework.model('user').ok === 1, 'framework: model() - 1');
454458
assert.ok(framework.model('other/products').ok === 2, 'framework: model() - 2');
455459

456-
assert.ok(self.isSecure === false, 'controller.isSecure');
460+
assert.ok(self.secured === false, 'controller.secured');
457461
assert.ok(self.config.isDefinition === true, 'definitions()');
458462

459463
assert.ok(!self.xhr, name + 'xhr');

test/test-framework-debug.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,24 @@ function test_routing(next) {
203203
}, null, { 'user-agent': 'bla bla iPad bla' });
204204
});
205205

206+
async.await('robot - 1', function(complete) {
207+
utils.request(url + '', 'GET', null, function(error, data, code, headers) {
208+
if (error)
209+
throw error;
210+
assert(data === 'ROBOT', 'robot routing problem 1');
211+
complete();
212+
}, null, { 'user-agent': 'I am Crawler' });
213+
});
214+
215+
async.await('robot - 2', function(complete) {
216+
utils.request(url + '', 'GET', null, function(error, data, code, headers) {
217+
if (error)
218+
throw error;
219+
assert(data !== 'ROBOT', 'robot routing problem 2');
220+
complete();
221+
}, null, { 'user-agent': 'Chrome' });
222+
});
223+
206224
async.await('binary', function(complete) {
207225
utils.request(url + 'binary/', ['get'], null, function(error, data, code, headers) {
208226
if (error)

test/test-framework-release.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,24 @@ function test_routing(next) {
203203
}, null, { 'user-agent': 'bla bla iPad bla' });
204204
});
205205

206+
async.await('robot - 1', function(complete) {
207+
utils.request(url + '', 'GET', null, function(error, data, code, headers) {
208+
if (error)
209+
throw error;
210+
assert(data === 'ROBOT', 'robot routing problem 1');
211+
complete();
212+
}, null, { 'user-agent': 'I am Crawler' });
213+
});
214+
215+
async.await('robot - 2', function(complete) {
216+
utils.request(url + '', 'GET', null, function(error, data, code, headers) {
217+
if (error)
218+
throw error;
219+
assert(data !== 'ROBOT', 'robot routing problem 2');
220+
complete();
221+
}, null, { 'user-agent': 'Chrome' });
222+
});
223+
206224
async.await('binary', function(complete) {
207225
utils.request(url + 'binary/', ['get'], null, function(error, data, code, headers) {
208226
if (error)

0 commit comments

Comments
 (0)