initial commit
This commit is contained in:
commit
48bfb61cc0
3
go.mod
Normal file
3
go.mod
Normal file
@ -0,0 +1,3 @@
|
||||
module git.yetaga.in/alazyreader/prusa-connect-local
|
||||
|
||||
go 1.18
|
55
main.go
Normal file
55
main.go
Normal file
@ -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
Executable file
BIN
static/favicon.ico
Executable file
Binary file not shown.
After Width: | Height: | Size: 1.1 KiB |
10
static/index.html
Executable file
10
static/index.html
Executable file
@ -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
Executable file
5
static/main.b322e2869b73e803bb67.css
Executable file
File diff suppressed because one or more lines are too long
1
static/main.b322e2869b73e803bb67.js
Executable file
1
static/main.b322e2869b73e803bb67.js
Executable file
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue
Block a user