Add more stub endpoints

This commit is contained in:
Kegan Dougal 2017-04-20 15:09:38 +01:00
parent f7f3077cfa
commit 2ed48c54a5
4 changed files with 67 additions and 6 deletions

View file

@ -63,11 +63,6 @@ func Login(req *http.Request, cfg config.ClientAPI) util.JSONResponse {
HomeServer: cfg.ServerName, HomeServer: cfg.ServerName,
}, },
} }
} else if req.Method == "OPTIONS" {
return util.JSONResponse{
Code: 200,
JSON: nil,
}
} }
return util.JSONResponse{ return util.JSONResponse{
Code: 405, Code: 405,

View file

@ -1,6 +1,7 @@
package routing package routing
import ( import (
"encoding/json"
"net/http" "net/http"
"github.com/gorilla/mux" "github.com/gorilla/mux"
@ -43,12 +44,72 @@ func Setup(servMux *http.ServeMux, httpClient *http.Client, cfg config.ClientAPI
return writers.SendEvent(req, vars["roomID"], vars["eventType"], vars["txnID"], &stateKey, cfg, queryAPI, producer) return writers.SendEvent(req, vars["roomID"], vars["eventType"], vars["txnID"], &stateKey, cfg, queryAPI, producer)
})), })),
) )
// Stub endpoints required by Riot
r0mux.Handle("/login", r0mux.Handle("/login",
make("login", util.NewJSONRequestHandler(func(req *http.Request) util.JSONResponse { make("login", util.NewJSONRequestHandler(func(req *http.Request) util.JSONResponse {
return readers.Login(req, cfg) return readers.Login(req, cfg)
})), })),
) )
r0mux.Handle("/pushrules/",
make("push_rules", util.NewJSONRequestHandler(func(req *http.Request) util.JSONResponse {
res := json.RawMessage(`{
"global": {
"content": [],
"override": [],
"room": [],
"sender": [],
"underride": []
}
}`)
return util.JSONResponse{
Code: 200,
JSON: &res,
}
})),
)
r0mux.Handle("/user/{userID}/filter",
make("make_filter", util.NewJSONRequestHandler(func(req *http.Request) util.JSONResponse {
return util.JSONResponse{
Code: 200,
JSON: struct{}{},
}
})),
)
r0mux.Handle("/user/{userID}/filter/{filterID}",
make("filter", util.NewJSONRequestHandler(func(req *http.Request) util.JSONResponse {
return util.JSONResponse{
Code: 200,
JSON: struct{}{},
}
})),
)
// Riot user settings
r0mux.Handle("/profile/{userID}",
make("profile", util.NewJSONRequestHandler(func(req *http.Request) util.JSONResponse {
return util.JSONResponse{
Code: 200,
JSON: struct{}{},
}
})),
)
r0mux.Handle("/account/3pid",
make("account_3pid", util.NewJSONRequestHandler(func(req *http.Request) util.JSONResponse {
res := json.RawMessage(`{"threepids":[]}`)
return util.JSONResponse{
Code: 200,
JSON: &res,
}
})),
)
servMux.Handle("/metrics", prometheus.Handler()) servMux.Handle("/metrics", prometheus.Handler())
servMux.Handle("/api/", http.StripPrefix("/api", apiMux)) servMux.Handle("/api/", http.StripPrefix("/api", apiMux))
} }

2
vendor/manifest vendored
View file

@ -98,7 +98,7 @@
{ {
"importpath": "github.com/matrix-org/util", "importpath": "github.com/matrix-org/util",
"repository": "https://github.com/matrix-org/util", "repository": "https://github.com/matrix-org/util",
"revision": "ec8896cd7d9ba6de6143c5f123d1e45413657e7d", "revision": "bc9d5e2d2f68a2ca279fce0fa2f28a91ecf301ed",
"branch": "master" "branch": "master"
}, },
{ {

View file

@ -111,6 +111,11 @@ func MakeJSONAPI(handler JSONRequestHandler) http.HandlerFunc {
logger := GetLogger(req.Context()) logger := GetLogger(req.Context())
logger.Print("Incoming request") logger.Print("Incoming request")
if req.Method == "OPTIONS" {
SetCORSHeaders(w)
w.WriteHeader(200)
return
}
res := handler.OnIncomingRequest(req) res := handler.OnIncomingRequest(req)
// Set common headers returned regardless of the outcome of the request // Set common headers returned regardless of the outcome of the request