diff --git a/.gitignore b/.gitignore
index 986f939..fbc63c1 100644
--- a/.gitignore
+++ b/.gitignore
@@ -6,4 +6,5 @@
__debug_bin
bin/
+static/
homeservice.tar.gz
diff --git a/go.mod b/go.mod
index 4ced99d..9bc8003 100644
--- a/go.mod
+++ b/go.mod
@@ -6,6 +6,6 @@ require github.com/eclipse/paho.mqtt.golang v1.4.2
require (
github.com/gorilla/websocket v1.4.2 // indirect
- golang.org/x/net v0.0.0-20200425230154-ff2c4b7c35a0 // indirect
+ golang.org/x/net v0.4.0 // indirect
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c // indirect
)
diff --git a/go.sum b/go.sum
index ddd8ce6..1e42071 100644
--- a/go.sum
+++ b/go.sum
@@ -3,8 +3,9 @@ github.com/eclipse/paho.mqtt.golang v1.4.2/go.mod h1:JGt0RsEwEX+Xa/agj90YJ9d9DH2
github.com/gorilla/websocket v1.4.2 h1:+/TMaTYc4QFitKJxsQ7Yye35DkWvkdLcvGKqM+x0Ufc=
github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
-golang.org/x/net v0.0.0-20200425230154-ff2c4b7c35a0 h1:Jcxah/M+oLZ/R4/z5RzfPzGbPXnVDPkEDtf2JnuxN+U=
golang.org/x/net v0.0.0-20200425230154-ff2c4b7c35a0/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
+golang.org/x/net v0.4.0 h1:Q5QPcMlvfxFTAPV0+07Xz/MpK9NTXu2VDUuy0FeMfaU=
+golang.org/x/net v0.4.0/go.mod h1:MBQ8lrhLObU/6UmLb4fmbmk5OcyYmqtbGd/9yIeKjEE=
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c h1:5KslGYwFpkhGh+Q16bwMP3cOontH8FOep7tGV86Y7SQ=
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
diff --git a/homeservice.service b/homeservice.service
index 247549f..3604d94 100644
--- a/homeservice.service
+++ b/homeservice.service
@@ -4,7 +4,7 @@ After=multi-user.target
[Service]
Type=idle
-ExecStart=/usr/bin/homeservice -c /etc/homeservice/config.json
+ExecStart=/usr/bin/homeservice -d /var/lib/home/
[Install]
WantedBy=multi-user.target
diff --git a/main.go b/main.go
index 822e8c0..a8185c2 100644
--- a/main.go
+++ b/main.go
@@ -2,8 +2,8 @@ package main
import (
"encoding/json"
+ "flag"
"log"
- "mime"
"net/http"
"sync"
@@ -73,6 +73,10 @@ func http_endpoint_sauna(w http.ResponseWriter, r *http.Request) {
func main() {
logger.Println("starting")
+ var webui_path string
+ flag.StringVar(&webui_path, "d", "./static", "Specify path to serve the web ui. Default is ./static")
+ flag.Parse()
+
// MQTT connection
opts := mqtt.NewClientOptions()
opts.AddBroker("tcp://nuc:1883")
@@ -91,11 +95,9 @@ func main() {
token.Wait()
logger.Printf("Subscribed to topic %s", topic)
- mime.AddExtensionType(".js", "text/javascript; charset=utf-8")
- mime.AddExtensionType(".css", "text/css; charset=utf-8")
// API routes
// Serve files from static folder
- http.Handle("/", http.FileServer(http.Dir("/var/lib/home/")))
+ http.Handle("/", http.FileServer(http.Dir(webui_path)))
http.HandleFunc("/sauna/sample", http_endpoint_sauna)
diff --git a/webui/Dockerfile b/webui/Dockerfile
new file mode 100644
index 0000000..f3918b0
--- /dev/null
+++ b/webui/Dockerfile
@@ -0,0 +1,11 @@
+FROM node:latest AS build
+WORKDIR /app
+COPY package.json ./
+COPY package-lock.json ./
+RUN npm install
+COPY . ./
+RUN npm run build
+
+FROM nginx:1.19-alpine
+COPY --from=build /app/build /usr/share/nginx/html
+
diff --git a/webui/package-lock.json b/webui/package-lock.json
index 71be6d4..9b92c43 100644
--- a/webui/package-lock.json
+++ b/webui/package-lock.json
@@ -8,7 +8,8 @@
"name": "my-app",
"version": "0.0.1",
"dependencies": {
- "@fontsource/fira-mono": "^4.5.0"
+ "@fontsource/fira-mono": "^4.5.0",
+ "svelte-spa-router": "^3.3.0"
},
"devDependencies": {
"@sveltejs/adapter-static": "next",
@@ -821,6 +822,14 @@
"node": "^10 || ^12 || >=14"
}
},
+ "node_modules/regexparam": {
+ "version": "2.0.1",
+ "resolved": "https://registry.npmjs.org/regexparam/-/regexparam-2.0.1.tgz",
+ "integrity": "sha512-zRgSaYemnNYxUv+/5SeoHI0eJIgTL/A2pUtXUPLHQxUldagouJ9p+K6IbIZ/JiQuCEv2E2B1O11SjVQy3aMCkw==",
+ "engines": {
+ "node": ">=8"
+ }
+ },
"node_modules/resolve": {
"version": "1.22.1",
"resolved": "https://registry.npmjs.org/resolve/-/resolve-1.22.1.tgz",
@@ -933,6 +942,17 @@
"svelte": ">=3.19.0"
}
},
+ "node_modules/svelte-spa-router": {
+ "version": "3.3.0",
+ "resolved": "https://registry.npmjs.org/svelte-spa-router/-/svelte-spa-router-3.3.0.tgz",
+ "integrity": "sha512-cwRNe7cxD43sCvSfEeaKiNZg3FCizGxeMcf7CPiWRP3jKXjEma3vxyyuDtPOam6nWbVxl9TNM3hlE/i87ZlqcQ==",
+ "dependencies": {
+ "regexparam": "2.0.1"
+ },
+ "funding": {
+ "url": "https://github.com/sponsors/ItalyPaleAle"
+ }
+ },
"node_modules/tiny-glob": {
"version": "0.2.9",
"resolved": "https://registry.npmjs.org/tiny-glob/-/tiny-glob-0.2.9.tgz",
@@ -1470,6 +1490,11 @@
"source-map-js": "^1.0.2"
}
},
+ "regexparam": {
+ "version": "2.0.1",
+ "resolved": "https://registry.npmjs.org/regexparam/-/regexparam-2.0.1.tgz",
+ "integrity": "sha512-zRgSaYemnNYxUv+/5SeoHI0eJIgTL/A2pUtXUPLHQxUldagouJ9p+K6IbIZ/JiQuCEv2E2B1O11SjVQy3aMCkw=="
+ },
"resolve": {
"version": "1.22.1",
"resolved": "https://registry.npmjs.org/resolve/-/resolve-1.22.1.tgz",
@@ -1547,6 +1572,14 @@
"dev": true,
"requires": {}
},
+ "svelte-spa-router": {
+ "version": "3.3.0",
+ "resolved": "https://registry.npmjs.org/svelte-spa-router/-/svelte-spa-router-3.3.0.tgz",
+ "integrity": "sha512-cwRNe7cxD43sCvSfEeaKiNZg3FCizGxeMcf7CPiWRP3jKXjEma3vxyyuDtPOam6nWbVxl9TNM3hlE/i87ZlqcQ==",
+ "requires": {
+ "regexparam": "2.0.1"
+ }
+ },
"tiny-glob": {
"version": "0.2.9",
"resolved": "https://registry.npmjs.org/tiny-glob/-/tiny-glob-0.2.9.tgz",
diff --git a/webui/package.json b/webui/package.json
index 8b7436f..69742d9 100644
--- a/webui/package.json
+++ b/webui/package.json
@@ -14,6 +14,7 @@
},
"type": "module",
"dependencies": {
- "@fontsource/fira-mono": "^4.5.0"
+ "@fontsource/fira-mono": "^4.5.0",
+ "svelte-spa-router": "^3.3.0"
}
}
diff --git a/webui/src/lib/Header.svelte b/webui/src/lib/Header.svelte
index f0d13ca..a790c8e 100644
--- a/webui/src/lib/Header.svelte
+++ b/webui/src/lib/Header.svelte
@@ -1,6 +1,6 @@