This repository was archived by the owner on Apr 21, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhandler.goasdf
More file actions
70 lines (59 loc) · 1.41 KB
/
Copy pathhandler.goasdf
File metadata and controls
70 lines (59 loc) · 1.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package main
import (
"io/ioutil"
"log"
"net/http"
"os"
"path/filepath"
"github.com/cueblox/blox/content"
"github.com/h2non/imaginary"
)
var repo *content.Service
var hf http.HandlerFunc
var h http.Handler
var imgHandler http.Handler
var static bool
var staticDir string
func init() {
userConfig, err := ioutil.ReadFile("blox.cue")
if err != nil {
log.Fatal(err)
}
repo, err := content.NewService(string(userConfig), true)
if err != nil {
log.Fatal(err)
}
hf, err = repo.GQLHandlerFunc()
if err != nil {
log.Fatal(err)
}
h, err = repo.GQLPlaygroundHandler()
if err != nil {
log.Fatal(err)
}
staticDir, err = repo.Cfg.GetString("static_dir")
if err != nil {
log.Println("No static_dir in config, not serving static files.")
} else {
log.Printf("Serving static files from %s\n", staticDir)
static = true
}
var options imaginary.ServeOptions
options.PathPrefix = "/img"
options.
imgHandler = imaginary.NewServerMux(options)
}
func main() {
listenAddr := ":8080"
if val, ok := os.LookupEnv("PORT"); ok {
listenAddr = ":" + val
}
if static {
http.Handle("/static/", http.StripPrefix("/static/", http.FileServer(http.Dir(filepath.Join(".", staticDir)))))
}
http.HandleFunc("/api", hf)
http.Handle("/api/ui", h)
http.Handle("/img", imgHandler)
log.Printf("About to listen on %s. Go to https://127.0.0.1%s/", listenAddr, listenAddr)
log.Fatal(http.ListenAndServe(listenAddr, nil))
}