forked from sbstjn/noduino
-
Notifications
You must be signed in to change notification settings - Fork 0
/
srv.app.js
50 lines (44 loc) · 1.57 KB
/
srv.app.js
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
/**
* srv.app.js – Handling HTTP:80 Requests
* This file is part of noduino (c) 2012 Sebastian Müller <c@semu.mp>
*
* @package noduino
* @author Sebastian Müller <c@semu.mp>
* @license MIT License – http://www.opensource.org/licenses/mit-license.php
* @url https://github.com/semu/noduino
*/
define(['kickstart', 'module', 'path', 'fs'], function (kickstart, module, path, fs) {
var kickstart = kickstart.withConfig({'name': 'localhost', 'port': 8080, 'path': './'});
var srv = kickstart.srv();
/**
* Load file with example snippets
*/
var fileContents = fs.readFileSync('./examples.snippet'),
sections = (fileContents + '').split('###'),
examples = {};
for (var i = 0; i < sections.length; i++) {
var tmp = sections[i].split("\n"),
key = tmp.shift();
tmp.pop();
examples[key] = tmp.join("\n");
}
/**
* Catch request for serving home page
*/
srv.all('/', function(req, res) {
res.render('home', {jsApp: 'main', active: 'home', title: 'noduino', 'examples': examples});
});
/**
* Catch request for Getting Started page
*/
srv.all('/getting-started.html', function(req, res) {
res.render('getting-started', {jsApp: 'none', active: 'getting-started', title: 'noduino', 'examples': examples});
});
/**
* Catch request for serving walkLED example page
*/
srv.all('/example-walkLED.html', function(req, res) {
res.render('example-walkLED', {jsApp: 'walkLED', active: 'examples', title: 'noduino', 'examples': examples});
});
return {'kickstart': kickstart, 'srv': srv};
});