mirror of
https://github.com/Unkn0wnCat/calapi.git
synced 2025-05-24 21:26:09 +02:00
Initial commit
This commit is contained in:
commit
15407746e3
37 changed files with 8525 additions and 0 deletions
28
internal/server/server.go
Normal file
28
internal/server/server.go
Normal file
|
@ -0,0 +1,28 @@
|
|||
package server
|
||||
|
||||
import (
|
||||
"github.com/99designs/gqlgen/graphql/handler"
|
||||
"github.com/99designs/gqlgen/graphql/playground"
|
||||
"github.com/Unkn0wnCat/calapi/graph"
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
)
|
||||
|
||||
const defaultPort = "8080"
|
||||
|
||||
func Serve() {
|
||||
port := os.Getenv("PORT")
|
||||
if port == "" {
|
||||
port = defaultPort
|
||||
}
|
||||
|
||||
srv := handler.NewDefaultServer(graph.NewExecutableSchema(graph.Config{Resolvers: &graph.Resolver{}}))
|
||||
|
||||
http.Handle("/", playground.Handler("GraphQL playground", "/query"))
|
||||
http.Handle("/query", srv)
|
||||
|
||||
log.Printf("connect to http://localhost:%s/ for GraphQL playground", port)
|
||||
log.Fatal(http.ListenAndServe(":"+port, nil))
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue