-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.go
47 lines (37 loc) · 906 Bytes
/
app.go
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
package main
import (
"flag"
"log"
"net/http"
"path"
"strconv"
"github.com/soapboxsys/ombudslib/jsonapi"
"github.com/soapboxsys/ombudslib/ombutil"
"github.com/soapboxsys/ombudslib/pubrecdb"
)
func main() {
defaultAppPath := ombutil.AppDataDir("ombnode", false)
var DBPath *string = flag.String(
"pubrecpath",
path.Join(defaultAppPath, "data", "testnet", "pubrecord.db"),
"Path to the public record database",
)
var port *int = flag.Int(
"port",
8080,
"Port to listen on.",
)
flag.Parse()
db, err := pubrecdb.LoadDB(*DBPath)
if err != nil {
log.Fatal(err)
}
apiPrefix := "/api/"
api := jsonapi.Handler(apiPrefix, db)
mux := http.NewServeMux()
mux.Handle(apiPrefix, api)
mux.Handle("/", http.FileServer(http.Dir("./static")))
host := "0.0.0.0:" + strconv.Itoa(*port)
log.Printf("Server listening on: %s\n", host)
log.Println(http.ListenAndServe(host, mux))
}