Browse Source

initial commit

master
David Ashby 2 months ago
commit
48bfb61cc0
  1. 3
      go.mod
  2. 55
      main.go
  3. BIN
      static/favicon.ico
  4. 10
      static/index.html
  5. 5
      static/main.b322e2869b73e803bb67.css
  6. 1
      static/main.b322e2869b73e803bb67.js

3
go.mod

@ -0,0 +1,3 @@
module git.yetaga.in/alazyreader/prusa-connect-local
go 1.18

55
main.go

@ -0,0 +1,55 @@
package main
import (
"bytes"
"flag"
"io"
"log"
"net/http"
"strings"
"time"
)
type Config struct {
PrinterHostname string
Port string
}
func main() {
var hostname string
flag.StringVar(&hostname, "hostname", "localhost", "Hostname the Prusa Connect API is available at (assumes http)")
var port string
flag.StringVar(&port, "port", "3000", "Local port to run server on")
config := Config{
PrinterHostname: "http://" + hostname,
Port: port,
}
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
if r.URL.Path == "index.html" || r.URL.Path == "/" {
http.ServeFile(w, r, "./static/")
} else if strings.HasSuffix(r.URL.Path, ".js") {
http.ServeFile(w, r, "./static/"+r.URL.Path)
} else if strings.HasSuffix(r.URL.Path, ".css") {
http.ServeFile(w, r, "./static/"+r.URL.Path)
} else if strings.HasSuffix(r.URL.Path, ".ico") {
http.ServeFile(w, r, "./static/"+r.URL.Path)
} else if strings.HasPrefix(r.URL.Path, "/api") {
resp, err := http.Get(config.PrinterHostname + r.URL.Path)
if err != nil {
log.Println(err)
http.NotFoundHandler().ServeHTTP(w, r)
} else {
b, err := io.ReadAll(resp.Body)
if err != nil {
log.Println(err)
http.NotFoundHandler().ServeHTTP(w, r)
}
http.ServeContent(w, r, "", time.Now(), bytes.NewReader(b))
}
} else {
http.NotFoundHandler().ServeHTTP(w, r)
}
})
http.ListenAndServe(":"+config.Port, nil)
}

BIN
static/favicon.ico

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

10
static/index.html

@ -0,0 +1,10 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Original Prusa Mini - Prusa Connect</title>
<link rel="shortcut icon" href="favicon.ico"><link href="main.b322e2869b73e803bb67.css" rel="stylesheet"></head>
<body>
<noscript>Your browser does not support JavaScript!</noscript>
<script type="text/javascript" src="main.b322e2869b73e803bb67.js"></script></body>
</html>

5
static/main.b322e2869b73e803bb67.css

File diff suppressed because one or more lines are too long

1
static/main.b322e2869b73e803bb67.js

File diff suppressed because one or more lines are too long
Loading…
Cancel
Save