52 lines
1.2 KiB
Go
52 lines
1.2 KiB
Go
// Copyright 2024 Patial Tech. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style
|
|
// license that can be found in the LICENSE file.
|
|
|
|
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"net/http"
|
|
|
|
"gitserver.in/patialtech/mux"
|
|
"gitserver.in/patialtech/mux/middleware"
|
|
"gitserver.in/patialtech/rano/cmd/server/handler"
|
|
"gitserver.in/patialtech/rano/config"
|
|
"gitserver.in/patialtech/rano/graph"
|
|
"gitserver.in/patialtech/rano/util/logger"
|
|
)
|
|
|
|
func main() {
|
|
r := mux.NewRouter()
|
|
|
|
r.Use(handler.Request())
|
|
|
|
// CORS
|
|
r.Use(middleware.CORS(middleware.CORSOption{
|
|
AllowedHeaders: []string{"Content-Type"},
|
|
MaxAge: 60,
|
|
}))
|
|
// Secure Headers
|
|
r.Use(middleware.Helmet(middleware.HelmetOption{
|
|
ContentSecurityPolicy: middleware.CSP{
|
|
ScriptSrc: []string{"self", "https://cdn.jsdelivr.net", "unsafe-inline"},
|
|
},
|
|
}))
|
|
|
|
// graphiql
|
|
r.GET("/graphiql", graph.GraphiQL("/query"))
|
|
// graph query
|
|
r.POST("/query", graph.Query)
|
|
|
|
// catch all
|
|
r.GET("/", func(w http.ResponseWriter, r *http.Request) {
|
|
w.Write([]byte("hello there"))
|
|
})
|
|
|
|
r.Serve(func(srv *http.Server) error {
|
|
srv.Addr = fmt.Sprintf(":%d", config.Read().GraphPort)
|
|
logger.Info("graph server listening on %s", srv.Addr)
|
|
return srv.ListenAndServe()
|
|
})
|
|
}
|