-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
47 lines (35 loc) · 1.14 KB
/
main.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
38
39
40
41
42
43
44
45
46
47
package main
import (
"fmt"
"net/http"
"os"
b64 "encoding/base64"
"github.com/gorilla/mux"
)
// go mod init github.com/Ulbora/cocka2notesPwaServer
func main() {
router := mux.NewRouter()
router.HandleFunc("/rs/config/get", config).Methods("GET")
//site pages
//router.HandleFunc("/", index).Methods("GET")
fmt.Println("Running on port 8080")
router.PathPrefix("/").Handler(http.FileServer(http.Dir("./static/")))
http.ListenAndServe(":8080", router)
}
func config(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
fmt.Println("Origin: ", r.Header.Get("Origin"))
fmt.Println("Host: ", r.Host)
fmt.Println("URL: ", r.URL)
var data string
if os.Getenv("COCKA2NOTE_CONFIG") != "" {
if r.Header.Get("Origin") == "www.cocka2notes.com" || r.Host == "www.cocka2notes.com" || r.Host == "localhost:8080" {
data = os.Getenv("COCKA2NOTE_CONFIG")
}
} else {
data = "ewogICAidXJsIjoiaHR0cDovL2xvY2FsaG9zdDozMDAwIiwKICAgImFwaUtleSI6IkdERzY1MUdGRDY2RkQxNjE1MXNzczY1MWY2NTFmZjY1NTU1ZGRmaGprbHl5NSIKfQ=="
}
rtn, _ := b64.StdEncoding.DecodeString(data)
fmt.Println(rtn)
fmt.Fprint(w, string(rtn))
}