-
Notifications
You must be signed in to change notification settings - Fork 226
/
srv.app.js
63 lines (54 loc) · 2.02 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
51
52
53
54
55
56
57
58
59
60
61
62
63
/**
* srv.app.js – Handling HTTP:80 Requests
* This file is part of noduino (c) 2012 Sebastian Müller <[email protected]>
*
* @package noduino
* @author Sebastian Müller <[email protected]>
* @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 args = process.argv.splice(2);
var hostname = args[0] || 'localhost';
var port = args[1] || 8080;
var host = hostname + ':' + port;
var kickstart = kickstart.withConfig({'name': hostname, 'port': port, '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', {hostname: hostname, 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', {hostname: hostname, 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', {hostname: hostname, jsApp: 'walkLED', active: 'examples', title: 'noduino', 'examples': examples});
});
/**
* Catch request for serving motor example
*/
srv.all('/example-motor.html', function(req, res) {
res.render('example-motor', {hostname: hostname, jsApp: 'motor', active: 'examples', title: 'noduino', 'examples': examples});
});
return {'kickstart': kickstart, 'srv': srv};
});