Skip to content

Commit

Permalink
Merge pull request #79 from bavix/refactoring
Browse files Browse the repository at this point in the history
refactoring
  • Loading branch information
rez1dent3 authored Dec 15, 2023
2 parents 77d076d + 11f9a1a commit ea39d98
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 12 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/compile-assets.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,7 @@ jobs:
ui:
permissions:
contents: write
uses: bavix/.github/.github/workflows/compile-assets.yml@0.1.0
uses: bavix/.github/.github/workflows/compile-assets.yml@0.0.4
secrets: inherit
with:
nodejs: 21.x
28 changes: 17 additions & 11 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,41 @@ package main

import (
"embed"
"github.com/bavix/boxpacker3-ui/internal/app"
"errors"
"io/fs"
"log"
"net"
"net/http"
"os"

"github.com/bavix/boxpacker3-ui/internal/app"
)

//go:embed public
var publicFiles embed.FS

func main() {
publicFS := fs.FS(publicFiles)
publicContent, err := fs.Sub(publicFS, "public")
htmlContent, err := fs.Sub(publicFiles, "public")
if err != nil {
log.Fatal(err)
}

http.Handle("/", http.FileServer(http.FS(publicContent)))
port := os.Getenv("PORT")
if port == "" {
port = "3000"
}
http.Handle("/", http.FileServer(http.FS(htmlContent)))

http.HandleFunc("/bp3", app.Bp3Handle)
http.HandleFunc("/bp3boxes", app.Bp3DefaultBoxesHandle)

log.Printf("Listening on :%s...", port)
err = http.ListenAndServe(":"+port, nil)
if err != nil {
host, _ := os.LookupEnv("HOST")
port, ok := os.LookupEnv("PORT")
if !ok {
port = "8080"
}

addr := net.JoinHostPort(host, port)
log.Printf("Listening on %s...\n", addr)

err = http.ListenAndServe(addr, nil)
if err != nil && !errors.Is(err, http.ErrServerClosed) {
log.Fatal(err)
}
}

0 comments on commit ea39d98

Please sign in to comment.