| giolekva | 0f503aa | 2020-04-20 22:41:06 +0400 | [diff] [blame^] | 1 | package main |
| 2 | |
| 3 | import ( |
| 4 | "flag" |
| 5 | "fmt" |
| 6 | "log" |
| 7 | "net/http" |
| 8 | ) |
| 9 | |
| 10 | var port = flag.Int("port", 3000, "Port to listen on") |
| 11 | |
| 12 | func handle_gallery(w http.ResponseWriter, r *http.Request) { |
| 13 | http.ServeFile(w, r, "./gallery.html") |
| 14 | } |
| 15 | |
| 16 | func handle_photo(w http.ResponseWriter, r *http.Request) { |
| 17 | http.ServeFile(w, r, "./photo.html") |
| 18 | } |
| 19 | |
| 20 | func handle_graphql(w http.ResponseWriter, r *http.Request) { |
| 21 | http.Redirect(w, r, "http://localhost:8080/graphql?query={queryImage(){id objectPath}}", http.StatusMovedPermanently) |
| 22 | } |
| 23 | |
| 24 | func main() { |
| 25 | flag.Parse() |
| 26 | fs := http.FileServer(http.Dir("./static")) |
| 27 | http.Handle("/static/", http.StripPrefix("/static/", fs)) |
| 28 | http.HandleFunc("/graphql", handle_graphql) |
| 29 | http.HandleFunc("/", handle_gallery) |
| 30 | log.Fatal(http.ListenAndServe(fmt.Sprintf(":%d", *port), nil)) |
| 31 | } |