1 | /*
|
2 |
|
3 | BSD LICENSED
|
4 |
|
5 | Copyright (c) 2011, Janne Julkunen
|
6 | All rights reserved.
|
7 |
|
8 | Redistribution and use in source and binary forms, with or without modification,
|
9 | are permitted provided that the following conditions are met:
|
10 |
|
11 | * Redistributions of source code must retain the above copyright notice, this
|
12 | list of conditions and the following disclaimer.
|
13 |
|
14 | * Redistributions in binary form must reproduce the above copyright notice,
|
15 | this list of conditions and the following disclaimer in the documentation
|
16 | and/or other materials provided with the distribution.
|
17 |
|
18 | * Neither the name of the Enlightened Linux Solutions nor the names of its
|
19 | contributors may be used to endorse or promote products derived from this
|
20 | software without specific prior written permission.
|
21 |
|
22 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
23 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
24 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
25 | IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
26 | INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
27 | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
28 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
29 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
|
30 | OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
31 | OF THE POSSIBILITY OF SUCH DAMAGE.
|
32 |
|
33 | */
|
34 |
|
35 | var express = require('express');
|
36 |
|
37 | var form = require('connect-form');
|
38 |
|
39 | var loaded = [];
|
40 |
|
41 | var modules = ["app-frontrow", "app-itunes", "app-mpd", "app-quicktime", "app-rhythmbox", "app-totem",
|
42 | "sys-1-wire", "sys-input", "sys-sound", "sys-surveillance"];
|
43 |
|
44 | console.log("Home Control server: starting");
|
45 |
|
46 | var srv = express.createServer(
|
47 | form({ keepExtensions: true })
|
48 | );
|
49 |
|
50 | srv.get("/status", function(req, res) {
|
51 | res.send(loaded);
|
52 | });
|
53 |
|
54 | for(var i = 0; i < modules.length; i++) {
|
55 | var module = require("./lib/" + modules[i]);
|
56 |
|
57 | module.setup(function(module, moduleID, moduleName, moduleCategory) {
|
58 | if((moduleID) && (moduleName) && (moduleCategory)) {
|
59 | console.log("Loading " + moduleCategory + " module: " + moduleName);
|
60 |
|
61 | srv.get("/" + moduleID + "/*", module.execute);
|
62 |
|
63 | srv.post("/" + moduleID + "/*", module.execute);
|
64 |
|
65 | loaded.push({id: moduleID, name: moduleName, category: moduleCategory});
|
66 | }
|
67 | }.bind(this, module));
|
68 | }
|
69 |
|
70 | srv.listen(3000);
|
71 |
|