This repository has been archived by the owner on Feb 27, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
web.go
63 lines (54 loc) · 1.41 KB
/
web.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package main
import (
"github.com/carbocation/interpose"
"github.com/carbocation/interpose/adaptors"
"github.com/gorilla/mux"
"github.com/jmcvetta/neoism"
"github.com/rs/cors"
"log"
"net/http"
"os"
"nodes/handlers"
)
var db *neoism.Database
func main() {
var err error
db, err = neoism.Connect(os.Getenv("NEO4J_URL"))
if err != nil {
log.Fatal(err)
}
// middleware
middle := interpose.New()
middle.Use(adaptors.FromNegroni(cors.New(cors.Options{
// CORS
AllowedOrigins: []string{"*"},
})))
// router
router := mux.NewRouter()
router.StrictSlash(true) // redirects '/path' to '/path/'
middle.UseHandler(router)
// ~
// > routes
router.HandleFunc("/rel/", func(w http.ResponseWriter, r *http.Request) {
handlers.CreateRelationship(db, w, r)
}).Methods("POST")
router.HandleFunc("/eql/", func(w http.ResponseWriter, r *http.Request) {
handlers.CreateEquality(db, w, r)
}).Methods("POST")
router.HandleFunc("/btw/", func(w http.ResponseWriter, r *http.Request) {
handlers.RelationshipsBetween(db, w, r)
}).Methods("GET")
router.HandleFunc("/cluster.svg", func(w http.ResponseWriter, r *http.Request) {
handlers.ViewRelationships(db, w, r)
}).Methods("GET")
// ~
// static files
router.PathPrefix("/").Handler(http.FileServer(http.Dir("./static/")))
// ~
port := os.Getenv("PORT")
if port == "" {
port = "5000"
}
log.Print("listening...")
http.ListenAndServe(":"+port, middle)
}