m
This commit is contained in:
@@ -3,6 +3,11 @@ package main
|
||||
import (
|
||||
"embed"
|
||||
"mime"
|
||||
"net/http"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"log"
|
||||
"time"
|
||||
@@ -32,6 +37,35 @@ func init() {
|
||||
// and starts a goroutine that emits a time-based event every second. It subsequently runs the application and
|
||||
// logs any error that might occur.
|
||||
func main() {
|
||||
defaultHandler := application.AssetFileServerFS(assets)
|
||||
|
||||
customAssetHandler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
path := r.URL.Path
|
||||
if strings.HasPrefix(path, "/assets/") {
|
||||
filename := strings.TrimPrefix(path, "/assets/")
|
||||
localPath := filepath.Join("assets", filename)
|
||||
if _, err := os.Stat(localPath); err == nil {
|
||||
http.ServeFile(w, r, localPath)
|
||||
return
|
||||
}
|
||||
}
|
||||
defaultHandler.ServeHTTP(w, r)
|
||||
})
|
||||
|
||||
quizService := NewQuizService()
|
||||
|
||||
serverHost := os.Getenv("WAILS_SERVER_HOST")
|
||||
if serverHost == "" {
|
||||
serverHost = "0.0.0.0"
|
||||
}
|
||||
|
||||
serverPortStr := os.Getenv("WAILS_SERVER_PORT")
|
||||
serverPort := 8080
|
||||
if serverPortStr != "" {
|
||||
if p, err := strconv.Atoi(serverPortStr); err == nil {
|
||||
serverPort = p
|
||||
}
|
||||
}
|
||||
|
||||
// Create a new Wails application by providing the necessary options.
|
||||
// Variables 'Name' and 'Description' are for application metadata.
|
||||
@@ -42,16 +76,22 @@ func main() {
|
||||
Name: "Master CBT",
|
||||
Description: "Learn everything with me",
|
||||
Services: []application.Service{
|
||||
application.NewService(NewQuizService()),
|
||||
application.NewService(quizService),
|
||||
},
|
||||
Assets: application.AssetOptions{
|
||||
Handler: application.AssetFileServerFS(assets),
|
||||
Handler: customAssetHandler,
|
||||
},
|
||||
Server: application.ServerOptions{
|
||||
Host: serverHost,
|
||||
Port: serverPort,
|
||||
},
|
||||
Mac: application.MacOptions{
|
||||
ApplicationShouldTerminateAfterLastWindowClosed: true,
|
||||
},
|
||||
})
|
||||
|
||||
quizService.SetApp(app)
|
||||
|
||||
// Create a new window with the necessary options.
|
||||
// 'Title' is the title of the window.
|
||||
// 'Mac' options tailor the window when running on macOS.
|
||||
|
||||
Reference in New Issue
Block a user