| 1 |
// +build ignore |
| 2 |
|
| 3 |
package main |
| 4 |
|
| 5 |
import ( |
| 6 |
"fmt" |
| 7 |
"log" |
| 8 |
"net/http" |
| 9 |
"os" |
| 10 |
"time" |
| 11 |
|
| 12 |
"github.com/gorilla/handlers" |
| 13 |
"github.com/gorilla/mux" |
| 14 |
) |
| 15 |
|
| 16 |
func main() { |
| 17 |
router := mux.NewRouter() |
| 18 |
|
| 19 |
loggingMiddleware := func(h http.Handler) http.Handler { |
| 20 |
return handlers.LoggingHandler(os.Stdout, h) |
| 21 |
} |
| 22 |
router.Use(loggingMiddleware) |
| 23 |
|
| 24 |
wd, err := os.Getwd() |
| 25 |
if err != nil { |
| 26 |
log.Panic(err) |
| 27 |
} |
| 28 |
// change this directory to point at a different Javascript frontend to serve |
| 29 |
httpStaticAssetsDir := http.Dir(fmt.Sprintf("%s/../frontends/axios/", wd)) |
| 30 |
|
| 31 |
router.PathPrefix("/").Handler(http.FileServer(httpStaticAssetsDir)) |
| 32 |
|
| 33 |
server := &http.Server{ |
| 34 |
Handler: router, |
| 35 |
Addr: "localhost:8081", |
| 36 |
ReadTimeout: 60 * time.Second, |
| 37 |
WriteTimeout: 60 * time.Second, |
| 38 |
} |
| 39 |
|
| 40 |
fmt.Println("starting http server on localhost:8081") |
| 41 |
log.Panic(server.ListenAndServe()) |
| 42 |
} |