diff options
| author | Mitja Felicijan <m@mitjafelicijan.com> | 2023-07-08 21:51:20 +0200 |
|---|---|---|
| committer | Mitja Felicijan <m@mitjafelicijan.com> | 2023-07-08 21:51:20 +0200 |
| commit | 47742e9fcaec60798f7d67202e4fa0c25c64b3a1 (patch) | |
| tree | 0210dbf9613d87d3ecb4236938ab2e0aea25abd6 /main.go | |
| parent | 6985a2075010bfe359e2ba42a1da180b7fbfe5ce (diff) | |
| download | jbmafp-47742e9fcaec60798f7d67202e4fa0c25c64b3a1.tar.gz | |
Added small embedded server
Diffstat (limited to 'main.go')
| -rw-r--r-- | main.go | 19 |
1 files changed, 16 insertions, 3 deletions
@@ -5,6 +5,7 @@ import ( "fmt" "html/template" "log" + "net/http" "os" "path" "path/filepath" @@ -91,6 +92,13 @@ func cleanHTMLTags(htmlString string) string { return cleanString } +func simpleServer(projectRoot string) { + fs := http.FileServer(http.Dir(path.Join(projectRoot, "public"))) + http.Handle("/", fs) + log.Println("Server started on http://localhost:6969") + log.Fatal(http.ListenAndServe(":6969", nil)) +} + func initializeProject(projectRoot string) { log.Println("Initializing new project") @@ -353,13 +361,14 @@ func main() { } var args struct { - Init bool `arg:"-i,--init" help:"initialize new project"` - Build bool `arg:"-b,--build" help:"build the website"` + Init bool `arg:"-i,--init" help:"initialize new project"` + Build bool `arg:"-b,--build" help:"build the website"` + Server bool `arg:"-s,--server" help:"simple embedded HTTP server"` } arg.MustParse(&args) - if !args.Init && !args.Build { + if !args.Init && !args.Build && !args.Server { fmt.Println("No arguments provided. Try using `jbmafp --help`") os.Exit(0) } @@ -371,4 +380,8 @@ func main() { if args.Build { buildProject(projectRoot) } + + if args.Server { + simpleServer(projectRoot) + } } |
