mirror of
https://git.mills.io/saltyim/saltyim.git
synced 2024-06-27 09:18:22 +00:00
Add a API Lookup Endpoint to get around this stupid CORS crap. /api/v1/lookup/:addr (#95)
closes: #59 Co-authored-by: James Mills <prologic@shortcircuit.net.au> Reviewed-on: https://git.mills.io/saltyim/saltyim/pulls/95 Reviewed-by: xuu <xuu@noreply@mills.io>
This commit is contained in:
parent
d6fcad992c
commit
b5f74b74f7
@ -33,6 +33,7 @@ func (a *API) initRoutes() {
|
||||
|
||||
router.GET("/ping", a.PingEndpoint())
|
||||
router.POST("/register", a.RegisterEndpoint())
|
||||
router.GET("/lookup/:addr", a.LookupEndpoint())
|
||||
}
|
||||
|
||||
// PingEndpoint ...
|
||||
@ -66,3 +67,15 @@ func (a *API) RegisterEndpoint() httprouter.Handle {
|
||||
http.Error(w, "Account Created", http.StatusCreated)
|
||||
}
|
||||
}
|
||||
|
||||
// LookupEndpoint ...
|
||||
func (a *API) LookupEndpoint() httprouter.Handle {
|
||||
return func(w http.ResponseWriter, r *http.Request, p httprouter.Params) {
|
||||
addr, err := saltyim.LookupAddr(p.ByName("addr"))
|
||||
if err != nil {
|
||||
http.Error(w, "Lookup Error", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
a.r.JSON(w, http.StatusOK, addr)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user