fix missing link calls

This commit is contained in:
Thomas Klaehn 2023-02-06 11:33:18 +01:00
parent 89a78993b5
commit 8c110e845b
10 changed files with 66 additions and 13 deletions

1
.gitignore vendored
View File

@ -6,4 +6,5 @@
__debug_bin __debug_bin
bin/ bin/
static/
homeservice.tar.gz homeservice.tar.gz

2
go.mod
View File

@ -6,6 +6,6 @@ require github.com/eclipse/paho.mqtt.golang v1.4.2
require ( require (
github.com/gorilla/websocket v1.4.2 // indirect 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 golang.org/x/sync v0.0.0-20210220032951-036812b2e83c // indirect
) )

3
go.sum
View File

@ -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 h1:+/TMaTYc4QFitKJxsQ7Yye35DkWvkdLcvGKqM+x0Ufc=
github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= 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/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.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 h1:5KslGYwFpkhGh+Q16bwMP3cOontH8FOep7tGV86Y7SQ=
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 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= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=

View File

@ -4,7 +4,7 @@ After=multi-user.target
[Service] [Service]
Type=idle Type=idle
ExecStart=/usr/bin/homeservice -c /etc/homeservice/config.json ExecStart=/usr/bin/homeservice -d /var/lib/home/
[Install] [Install]
WantedBy=multi-user.target WantedBy=multi-user.target

10
main.go
View File

@ -2,8 +2,8 @@ package main
import ( import (
"encoding/json" "encoding/json"
"flag"
"log" "log"
"mime"
"net/http" "net/http"
"sync" "sync"
@ -73,6 +73,10 @@ func http_endpoint_sauna(w http.ResponseWriter, r *http.Request) {
func main() { func main() {
logger.Println("starting") 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 // MQTT connection
opts := mqtt.NewClientOptions() opts := mqtt.NewClientOptions()
opts.AddBroker("tcp://nuc:1883") opts.AddBroker("tcp://nuc:1883")
@ -91,11 +95,9 @@ func main() {
token.Wait() token.Wait()
logger.Printf("Subscribed to topic %s", topic) 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 // API routes
// Serve files from static folder // 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) http.HandleFunc("/sauna/sample", http_endpoint_sauna)

11
webui/Dockerfile Normal file
View File

@ -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

View File

@ -8,7 +8,8 @@
"name": "my-app", "name": "my-app",
"version": "0.0.1", "version": "0.0.1",
"dependencies": { "dependencies": {
"@fontsource/fira-mono": "^4.5.0" "@fontsource/fira-mono": "^4.5.0",
"svelte-spa-router": "^3.3.0"
}, },
"devDependencies": { "devDependencies": {
"@sveltejs/adapter-static": "next", "@sveltejs/adapter-static": "next",
@ -821,6 +822,14 @@
"node": "^10 || ^12 || >=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": { "node_modules/resolve": {
"version": "1.22.1", "version": "1.22.1",
"resolved": "https://registry.npmjs.org/resolve/-/resolve-1.22.1.tgz", "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.22.1.tgz",
@ -933,6 +942,17 @@
"svelte": ">=3.19.0" "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": { "node_modules/tiny-glob": {
"version": "0.2.9", "version": "0.2.9",
"resolved": "https://registry.npmjs.org/tiny-glob/-/tiny-glob-0.2.9.tgz", "resolved": "https://registry.npmjs.org/tiny-glob/-/tiny-glob-0.2.9.tgz",
@ -1470,6 +1490,11 @@
"source-map-js": "^1.0.2" "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": { "resolve": {
"version": "1.22.1", "version": "1.22.1",
"resolved": "https://registry.npmjs.org/resolve/-/resolve-1.22.1.tgz", "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.22.1.tgz",
@ -1547,6 +1572,14 @@
"dev": true, "dev": true,
"requires": {} "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": { "tiny-glob": {
"version": "0.2.9", "version": "0.2.9",
"resolved": "https://registry.npmjs.org/tiny-glob/-/tiny-glob-0.2.9.tgz", "resolved": "https://registry.npmjs.org/tiny-glob/-/tiny-glob-0.2.9.tgz",

View File

@ -14,6 +14,7 @@
}, },
"type": "module", "type": "module",
"dependencies": { "dependencies": {
"@fontsource/fira-mono": "^4.5.0" "@fontsource/fira-mono": "^4.5.0",
"svelte-spa-router": "^3.3.0"
} }
} }

View File

@ -1,6 +1,6 @@
<script> <script>
import perinetLogo from '../../static/perinet-logo.png' // import perinetLogo from '../../static/perinet-logo.png'
import favicon from '../../static/favicon.png' // import favicon from '../../static/favicon.png'
</script> </script>
<header class="header"> <header class="header">

View File

@ -4,8 +4,12 @@ import adapter from '@sveltejs/adapter-static';
const config = { const config = {
kit: { kit: {
adapter: adapter({ adapter: adapter({
fallback: "200.html" pages: '../static',
}) assets: '../static',
// fallback: '200.html',
precompress: false,
}),
trailingSlash: 'always'
} }
}; };