Add swagger to dockerfile, move js

This commit is contained in:
Florian Hoss 2022-10-21 12:41:47 +02:00
parent f06b124737
commit 2e3924d333
4 changed files with 19 additions and 22 deletions

View file

@ -2,6 +2,10 @@ FROM golang:alpine AS go
RUN apk add nodejs npm
WORKDIR /backend
COPY /backend/swagger.sh .
RUN chmod +x swagger.sh
RUN ./swagger.sh install
COPY ./go.mod .
RUN go mod download
@ -11,6 +15,7 @@ RUN npm install
COPY . .
RUN npm run build
RUN ./swagger.sh init
RUN go build -o app
FROM alpine AS logo

13
static/js/app.js Normal file
View file

@ -0,0 +1,13 @@
const WsType = { Weather: 0, System: 1 };
let socket = new WebSocket(window.location.origin.replace("http", "ws") + "/api/system/ws");
const weatherIcon = document.getElementById("weatherIcon");
const weatherTemp = document.getElementById("weatherTemp");
socket.onmessage = (event) => {
const parsed = JSON.parse(event.data);
if (parsed.ws_type === WsType.Weather) {
const weather = parsed.message;
weatherIcon.setAttribute("xlink:href", "#" + weather.weather[0].icon);
weatherTemp.innerHTML = parsed.message.main.temp + " " + parsed.message.units;
}
};

View file

@ -21,16 +21,15 @@
}
</style>
<link rel="stylesheet" href="/static/css/style.css" />
<script type="module" src="/static/js/app.js"></script>
</head>
<body class="bg-slate-100 dark:bg-slate-800 text-slate-800 dark:text-slate-50">
<div class="mx-auto max-w-7xl px-5 lg:px-8 my-3 md:my-10 lg:my-18 xl:my-28">{{ template "content" . }}</div>
{{ template "scripts" . }}
</body>
</html>
{{ end }}
{{ define "scripts" }}{{ end }}
{{ define "content" }}{{ end }}
{{ define "weatherIcons" }}

View file

@ -70,23 +70,3 @@
{{ end }}
</div>
{{ end }}
{{ define "scripts" }}
<script lang="ts">
import { weather_OpenWeatherApiResponse } from "./openapi";
const WsType = { Weather: 0, System: 1 };
let socket = new WebSocket(window.location.origin.replace("http", "ws") + "/api/system/ws");
const weatherIcon = document.getElementById("weatherIcon");
const weatherTemp = document.getElementById("weatherTemp");
socket.onmessage = (event) => {
const parsed = JSON.parse(event.data);
if (parsed.ws_type === WsType.Weather) {
const weather: weather_OpenWeatherApiResponse = parsed.message;
weatherIcon.setAttribute("xlink:href", "#" + weather.weather[0].icon);
weatherTemp.innerHTML = parsed.message.main.temp + " " + parsed.message.units;
}
};
</script>
{{ end }}