-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathmain.go
More file actions
35 lines (28 loc) · 647 Bytes
/
main.go
File metadata and controls
35 lines (28 loc) · 647 Bytes
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
package main
import (
"fmt"
"log"
"net/http"
"github.com/graphql-go/handler"
)
var db mongoDB
func main() {
fmt.Println("Golang+GraphQL+MongoDB Server v1.0.0")
// MongoDB
db = connectDB()
defer db.closeDB()
// GraphQL
schema := initSchema()
h := handler.New(&handler.Config{
Schema: &schema,
Pretty: true,
GraphiQL: true, // GraphiQL interface
})
// Serve
http.Handle("/", http.FileServer(http.Dir("./public"))) // Serve the frontend in /public
http.Handle("/graphql", disableCors(headerAuthorization(h)))
err := http.ListenAndServe(config.serveUri, nil)
if err != nil {
log.Fatal("ListenAndServe: ", err)
}
}