forked from totaljs/examples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdefault.js
More file actions
72 lines (56 loc) · 1.61 KB
/
default.js
File metadata and controls
72 lines (56 loc) · 1.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
exports.install = function() {
F.route('/', view_homepage);
F.route('/contact/', view_contact);
F.route('/products/', view_products);
F.route('/products/{category}/', view_products);
F.route('/products/{category}/{subcategory}/', view_products);
F.route('/{category}/', view_homepage);
// this route has a lower priority and it will be executed when:
// url: /asterix/
// url: /asterix/bla/bla/bla/bla/
F.route('/asterix/*', view_asterix);
// route: all txt files
// Try: http://127.0.0.4/test.txt
F.file('*.txt', static_txt);
// route: all jpg files
// all images will resized about 50%
// Try: http://127.0.0.4/header.jpg
F.file('*.jpg', static_jpg);
}
function static_txt(req, res) {
// responds
// this === framework
res.content(200, 'Server time: ' + new Date().toString(), 'text/plain');
}
function static_jpg(req, res) {
// responds
// this === framework
res.image(F.path.public(req.url), function (image) {
// image === FrameworkImage
image.resize('50%');
image.quality(80);
image.minify();
});
}
function view_homepage(category) {
category = category || '';
if (category.length)
category = ' -> ' + category;
this.plain('homepage{0}'.format(category));
}
function view_contact() {
this.plain('contact');
}
function view_products(category, subcategory) {
category = category || '';
subcategory = subcategory || '';
if (category.length)
category = ' -> ' + category;
if (subcategory.length)
subcategory = ' -> ' + subcategory;
this.plain('products{0}{1}'.format(category, subcategory));
}
function view_asterix() {
var self = this;
self.plain('asterix -> ' + self.uri.pathname);
}