UNPKG

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