-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
48 lines (38 loc) · 1.22 KB
/
index.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
import express from "express";
import path from "path";
import sqlite3 from "sqlite3";
import fetch from "node-fetch";
import {Section} from './public/js/app.js';
import { fileURLToPath } from 'url';
import { dirname } from 'path';
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
const app = express();
const wledIp = "192.168.3.117";
let numLeds = 0;
fetch("http://"+wledIp+"/json/info")
.then(res => res.json())
.then(json => numLeds = json.leds.count);
let getSections = () => {
return [
{length: numLeds, reverse: false, mirror: false}
]
};
const db = new sqlite3.Database("db.sqlite", (err) => {
if (err) {
// Cannot open database
console.error(err.message);
throw err;
} else {
console.log("Connected to the SQLite database.");
}
});
app.use(express.static(path.join(__dirname, "public")));
app.get("/", function (req, res) {
res.sendFile(path.join(__dirname, "public/index.html"));
});
app.get("/sections", function(req, res) {
let sections = getSections().map(x => new Section(x.length, x.reverse, x.mirror))
res.status(200).json(sections)
});
app.listen(8000, () => console.log("Server is running on Port 8000"));