Browse Source

Add swagger to dockerfile, move js

Florian Hoss 2 years ago
parent
commit
2e3924d333
4 changed files with 19 additions and 22 deletions
  1. 5 0
      Dockerfile
  2. 13 0
      static/js/app.js
  3. 1 2
      templates/_base.gohtml
  4. 0 20
      templates/index.gohtml

+ 5 - 0
Dockerfile

@@ -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 - 0
static/js/app.js

@@ -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;
+  }
+};

+ 1 - 2
templates/_base.gohtml

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

+ 0 - 20
templates/index.gohtml

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