2024-11-01 14:25:30 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2024-11-04 06:05:43 +00:00
|
|
|
"fmt"
|
2024-11-01 14:25:30 +00:00
|
|
|
"net/http"
|
|
|
|
|
|
|
|
"gitserver.in/patialtech/mux"
|
2024-11-04 06:05:43 +00:00
|
|
|
"gitserver.in/patialtech/mux/middleware"
|
|
|
|
"gitserver.in/patialtech/rano/config"
|
2024-11-01 14:25:30 +00:00
|
|
|
"gitserver.in/patialtech/rano/graph"
|
2024-11-15 16:12:15 +00:00
|
|
|
"gitserver.in/patialtech/rano/util/logger"
|
2024-11-01 14:25:30 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
r := mux.NewRouter()
|
2024-11-04 06:05:43 +00:00
|
|
|
// 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"},
|
|
|
|
},
|
|
|
|
}))
|
|
|
|
|
2024-11-01 14:25:30 +00:00
|
|
|
// graphiql
|
2024-11-04 06:05:43 +00:00
|
|
|
r.GET("/graphiql", graph.GraphiQL("/query"))
|
2024-11-01 14:25:30 +00:00
|
|
|
// graph query
|
2024-11-04 06:05:43 +00:00
|
|
|
r.POST("/query", graph.Query)
|
2024-11-01 14:25:30 +00:00
|
|
|
|
|
|
|
// catch all
|
2024-11-04 06:05:43 +00:00
|
|
|
r.GET("/", func(w http.ResponseWriter, r *http.Request) {
|
2024-11-01 14:25:30 +00:00
|
|
|
w.Write([]byte("hello there"))
|
|
|
|
})
|
|
|
|
|
|
|
|
r.Serve(func(srv *http.Server) error {
|
2024-11-04 06:05:43 +00:00
|
|
|
srv.Addr = fmt.Sprintf(":%d", config.Read().GraphPort)
|
2024-11-01 14:25:30 +00:00
|
|
|
logger.Info("graph server listening on %s", srv.Addr)
|
|
|
|
return srv.ListenAndServe()
|
|
|
|
})
|
|
|
|
}
|