github.com/maeglindeveloper/gqlgen@v0.13.1-0.20210413081235-57808b12a0a0/graphql/playground/playground.go (about)

     1  package playground
     2  
     3  import (
     4  	"html/template"
     5  	"net/http"
     6  )
     7  
     8  var page = template.Must(template.New("graphiql").Parse(`<!DOCTYPE html>
     9  <html>
    10  <head>
    11  	<meta charset=utf-8/>
    12  	<meta name="viewport" content="user-scalable=no, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, minimal-ui">
    13  	<link rel="shortcut icon" href="https://graphcool-playground.netlify.com/favicon.png">
    14  	<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/graphql-playground-react@{{ .version }}/build/static/css/index.css"
    15  		integrity="{{ .cssSRI }}" crossorigin="anonymous"/>
    16  	<link rel="shortcut icon" href="https://cdn.jsdelivr.net/npm/graphql-playground-react@{{ .version }}/build/favicon.png"
    17  		integrity="{{ .faviconSRI }}" crossorigin="anonymous"/>
    18  	<script src="https://cdn.jsdelivr.net/npm/graphql-playground-react@{{ .version }}/build/static/js/middleware.js"
    19  		integrity="{{ .jsSRI }}" crossorigin="anonymous"></script>
    20  	<title>{{.title}}</title>
    21  </head>
    22  <body>
    23  <style type="text/css">
    24  	html { font-family: "Open Sans", sans-serif; overflow: hidden; }
    25  	body { margin: 0; background: #172a3a; }
    26  </style>
    27  <div id="root"/>
    28  <script type="text/javascript">
    29  	window.addEventListener('load', function (event) {
    30  		const root = document.getElementById('root');
    31  		root.classList.add('playgroundIn');
    32  		const wsProto = location.protocol == 'https:' ? 'wss:' : 'ws:'
    33  		GraphQLPlayground.init(root, {
    34  			endpoint: location.protocol + '//' + location.host + '{{.endpoint}}',
    35  			subscriptionsEndpoint: wsProto + '//' + location.host + '{{.endpoint }}',
    36             shareEnabled: true,
    37  			settings: {
    38  				'request.credentials': 'same-origin'
    39  			}
    40  		})
    41  	})
    42  </script>
    43  </body>
    44  </html>
    45  `))
    46  
    47  func Handler(title string, endpoint string) http.HandlerFunc {
    48  	return func(w http.ResponseWriter, r *http.Request) {
    49  		w.Header().Add("Content-Type", "text/html")
    50  		err := page.Execute(w, map[string]string{
    51  			"title":      title,
    52  			"endpoint":   endpoint,
    53  			"version":    "1.7.26",
    54  			"cssSRI":     "sha256-dKnNLEFwKSVFpkpjRWe+o/jQDM6n/JsvQ0J3l5Dk3fc=",
    55  			"faviconSRI": "sha256-GhTyE+McTU79R4+pRO6ih+4TfsTOrpPwD8ReKFzb3PM=",
    56  			"jsSRI":      "sha256-SG9YAy4eywTcLckwij7V4oSCG3hOdV1m+2e1XuNxIgk=",
    57  		})
    58  		if err != nil {
    59  			panic(err)
    60  		}
    61  	}
    62  }