-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.go
37 lines (28 loc) · 947 Bytes
/
server.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
package main
import (
"github.com/nicotanzil/backend-gqlgen/app/middleware"
"github.com/nicotanzil/backend-gqlgen/database"
"github.com/nicotanzil/backend-gqlgen/graph/resolver"
"log"
"net/http"
"os"
"github.com/99designs/gqlgen/graphql/handler"
"github.com/99designs/gqlgen/graphql/playground"
"github.com/nicotanzil/backend-gqlgen/graph/generated"
)
const defaultPort = "8080"
func main() {
port := os.Getenv("PORT")
if port == "" {
port = defaultPort
}
srv := handler.NewDefaultServer(generated.NewExecutableSchema(generated.Config{Resolvers: &resolver.Resolver{}}))
wrapped := middleware.CorsMiddleware(srv)
wrapped = middleware.AuthMiddleware(wrapped)
http.Handle("/", playground.Handler("GraphQL playground", "/query"))
http.Handle("/query", wrapped)
database.Migrate()
database.Seed()
log.Printf("connect to http://localhost:%s/ for GraphQL playground", port)
log.Fatal(http.ListenAndServe(":"+port, nil))
}