-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.go
37 lines (33 loc) · 935 Bytes
/
script.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 server
import (
_ "embed"
"fmt"
"github.com/cwkr/auth-server/internal/httputil"
"log"
"net/http"
"time"
)
var (
//go:embed scripts/jwt.js
jwtScriptContent string
//go:embed scripts/main.js
mainScriptContent string
)
func JwtScriptHandler() http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
log.Printf("%s %s", r.Method, r.URL)
w.Header().Set("Content-Type", "text/javascript")
w.Header().Set("Content-Length", fmt.Sprint(len(jwtScriptContent)))
httputil.Cache(w, 120*time.Hour)
fmt.Fprint(w, jwtScriptContent)
})
}
func MainScriptHandler() http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
log.Printf("%s %s", r.Method, r.URL)
w.Header().Set("Content-Type", "text/javascript")
w.Header().Set("Content-Length", fmt.Sprint(len(mainScriptContent)))
httputil.Cache(w, 120*time.Hour)
fmt.Fprint(w, mainScriptContent)
})
}