-
Notifications
You must be signed in to change notification settings - Fork 2
/
server.js
36 lines (30 loc) · 1.02 KB
/
server.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
const fs = require("fs");
const http = require("http");
const route = require("./router").route;
const url = require("url");
const PORT = 9191;
let username = null;
try {
username = JSON.parse(fs.readFileSync("config.json", {encoding: "utf8"})).username;
} catch(err) {
console.log(`config.json not found - please press the link button on your Hue bridge and open localhost:${PORT}/createuser in your browser. \n${err}`);
}
const api = require("./api")(process.argv[2], username);
const handle = {
"/": api.indexServe,
"/getlights": api.getLights,
"/setlight": api.setLight,
"/createuser": api.createUser,
"/js/dancer.js": api.dancer,
"/js/jquery.js": api.jQuery,
"/js/index.js": api.indexJs,
"/css/index.css": api.indexCss,
"/mp3/wantyougone": api.mp3
}
function onRequest(req, res) {
const pathname = url.parse(req.url).pathname;
console.log(`Request for ${pathname} received`);
route(handle, pathname, req, res);
}
http.createServer(onRequest).listen(PORT);
console.log(`Server started on port ${PORT}`);