Repository navigation
Expand file tree
/
Copy pathmain.go
More file actions
110 lines (86 loc) · 3.24 KB
/
Copy pathmain.go
File metadata and controls
110 lines (86 loc) · 3.24 KB
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
package main
import (
// "embed"
"fmt"
"log"
"net/http"
"os"
"github.com/bigspaceships/circlejerk/auth"
"github.com/bigspaceships/circlejerk/queue"
dq_websocket "github.com/bigspaceships/circlejerk/websocket"
"github.com/joho/godotenv"
)
// TODO: figure this bit out
//ree go:embed static
// var server embed.FS
func ping(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "%s\n", auth.GetUserClaims(r))
}
func main() {
err := godotenv.Load()
if err != nil {
log.Println("No env file detected, make sure all secrets are loaded into the environment")
// panic("Error loading .env file")
}
cshAuth := auth.Config{
ClientId: os.Getenv("CSH_OIDC_CLIENT_ID"),
ClientSecret: os.Getenv("CSH_OIDC_CLIENT_SECRET"),
Issuer: os.Getenv("CSH_ISSUER"),
IssuerShort: "csh",
State: os.Getenv("STATE"),
RedirectURI: os.Getenv("HOST") + "/auth/callback-csh",
AuthURI: os.Getenv("HOST") + "/auth/login-csh",
}
googleAuth := auth.Config{
ClientId: os.Getenv("GOOGLE_OIDC_CLIENT_ID"),
ClientSecret: os.Getenv("GOOGLE_OIDC_CLIENT_SECRET"),
Issuer: os.Getenv("GOOGLE_ISSUER"),
IssuerShort: "google",
State: os.Getenv("STATE"),
RedirectURI: os.Getenv("HOST") + "/auth/callback-google",
AuthURI: os.Getenv("HOST") + "/auth/login-google",
}
cshAuth.SetupAuth()
googleAuth.SetupAuth()
port := os.Getenv("PORT")
if port == "" {
port = "8080"
}
ws_server := dq_websocket.CreateWSServer()
discussion := queue.SetupDiscussion(ws_server)
fs := http.FileServer(http.Dir("./static"))
http.HandleFunc("/auth/login-csh", cshAuth.LoginRequest)
http.HandleFunc("/auth/callback-csh", cshAuth.LoginCallback)
http.HandleFunc("/auth/login-google", googleAuth.LoginRequest)
http.HandleFunc("/auth/callback-google", googleAuth.LoginCallback)
apiMux := http.NewServeMux()
apiMux.HandleFunc("POST /queue/{queue}/point", discussion.NewPoint)
apiMux.HandleFunc("POST /queue/{queue}/clarifier", discussion.NewClarifier)
apiMux.HandleFunc("DELETE /queue/{queue}/point/{id}", discussion.DeletePoint)
apiMux.HandleFunc("DELETE /queue/{queue}/clarifier/{id}", discussion.DeleteClarifier)
apiMux.HandleFunc("PATCH /queue/{queue}", discussion.ChangeTopic)
apiMux.HandleFunc("GET /queue/{queue}", discussion.GetQueue)
apiMux.HandleFunc("POST /queue/{queue}/new-child", discussion.NewQueue)
apiMux.HandleFunc("DELETE /queue/{queue}", discussion.DeleteQueue)
apiMux.HandleFunc("GET /queue/{queue}/path", discussion.GetQueuePath)
apiMux.HandleFunc("GET /discussion", discussion.GetDiscussion)
apiMux.HandleFunc("PUT /discussion/reset", discussion.ResetDiscussion)
apiMux.HandleFunc("/joinws", ws_server.WebsocketConnect)
http.Handle("/api/", http.StripPrefix("/api", auth.Handler(apiMux)))
http.Handle("/auth", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
http.ServeFile(w, r, "static/auth.html")
}))
http.Handle("/auth/logout", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
cookie := &http.Cookie{
Name: "Auth",
Value: "",
MaxAge: -1,
Path: "/",
}
http.SetCookie(w, cookie)
http.Redirect(w, r, "/auth", http.StatusFound)
}))
http.Handle("/", fs)
log.Printf("Dairy Queue started on port %s\n", port)
log.Fatal(http.ListenAndServe(":"+port, nil))
}