forked from flohansen/hsfl-master-ai-cloud-engineering
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(web-service): add webserver to main.go
- Loading branch information
Dorien Grönwald
committed
Oct 31, 2023
1 parent
1acbe4c
commit 5824036
Showing
8 changed files
with
59 additions
and
118 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<script lang="ts"> | ||
import { base } from '$app/paths'; | ||
</script> | ||
|
||
<nav> | ||
<a href="{base}/">Home</a> | ||
</nav> | ||
<slot /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
// this is needed to give us force prerendering of all pages | ||
export const prerender = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<script lang="ts"> | ||
</script> | ||
|
||
<h1>Combining SvelteKit and Golang server</h1> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
module hsfl.de/group6/hsfl-master-ai-cloud-engineering/web-service | ||
|
||
go 1.21 | ||
|
||
require github.com/munxar/goapi v0.0.0-20230125125843-fe3f706866d0 // indirect |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,26 @@ | ||
package main | ||
|
||
import ( | ||
"hsfl.de/group6/hsfl-master-ai-cloud-engineering/web-service/api/router" | ||
"hsfl.de/group6/hsfl-master-ai-cloud-engineering/web-service/service" | ||
"log" | ||
"net/http" | ||
"path/filepath" | ||
) | ||
|
||
func main() { | ||
productsController := service.NewDefaultController() | ||
handler := router.New(productsController) | ||
buildDir := "frontend/build" | ||
|
||
if err := http.ListenAndServe(":3000", handler); err != nil { | ||
log.Fatalf("error while listen and serve: %s", err.Error()) | ||
fileServer := http.FileServer(http.Dir(buildDir)) | ||
|
||
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { | ||
if r.URL.Path == "/" { | ||
http.ServeFile(w, r, filepath.Join(buildDir, "index.html")) | ||
return | ||
} | ||
|
||
fileServer.ServeHTTP(w, r) | ||
}) | ||
|
||
err := http.ListenAndServe(":3000", nil) | ||
if err != nil { | ||
panic(err) | ||
} | ||
} |