-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
52 lines (43 loc) · 1 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package main
import (
"log"
"net/http"
"net/http/httputil"
"net/url"
"time"
)
const localFrontendURL = "http://localhost:5173/"
func serveFrontend(env string) http.Handler {
if env == "dev" {
target, _ := url.Parse(localFrontendURL)
proxy := httputil.NewSingleHostReverseProxy(target)
log.Println("Proxying frontend to Vite on port 8080")
return proxy
}
//serve from embedded files
log.Println("Serving frontend from embedded files")
fs := http.FileServer(http.FS(embeddedFiles))
return http.StripPrefix("/", fs)
}
var env = "prod"
func main() {
mux := http.NewServeMux()
//handlers
if env == "prod" {
log.Println("Running in prod mode")
return
}
log.Println("Running in dev mode")
mux.Handle("/", serveFrontend(env))
server := http.Server{
Addr: ":8080",
Handler: mux,
ReadTimeout: time.Minute,
WriteTimeout: time.Minute,
IdleTimeout: time.Minute,
}
log.Println("Starting server on port 8080")
if err := server.ListenAndServe(); err != nil {
panic(err)
}
}