Handle centralized app state and registration + chat history

This commit is contained in:
Gabe Kangas
2022-05-02 17:45:22 -07:00
parent b590e4f765
commit a0354d6d49
11 changed files with 257 additions and 45 deletions

View File

@ -18,6 +18,7 @@ func ExternalGetChatMessages(integration user.ExternalAPIUser, w http.ResponseWr
// GetChatMessages gets all of the chat messages.
func GetChatMessages(u user.User, w http.ResponseWriter, r *http.Request) {
middleware.EnableCors(w)
getChatMessages(w, r)
}
@ -41,7 +42,16 @@ func getChatMessages(w http.ResponseWriter, r *http.Request) {
// RegisterAnonymousChatUser will register a new user.
func RegisterAnonymousChatUser(w http.ResponseWriter, r *http.Request) {
if r.Method != POST {
middleware.EnableCors(w)
if r.Method == "OPTIONS" {
// All OPTIONS requests should have a wildcard CORS header.
w.Header().Set("Access-Control-Allow-Origin", "*")
w.WriteHeader(http.StatusNoContent)
return
}
if r.Method != http.MethodPost {
WriteSimpleResponse(w, false, r.Method+" not supported")
return
}