Allow CORS in ranking API
This commit is contained in:
parent
252d021d90
commit
5a592c505b
@ -10,6 +10,7 @@ import (
|
||||
|
||||
// Ranking returns the ranking information for the character via the API.
|
||||
func Ranking(ctx *aero.Context) string {
|
||||
// Check character ID
|
||||
id := ctx.Get("id")
|
||||
_, err := arn.GetCharacter(id)
|
||||
|
||||
@ -17,17 +18,24 @@ func Ranking(ctx *aero.Context) string {
|
||||
return ctx.Error(http.StatusNotFound, "Character not found", err)
|
||||
}
|
||||
|
||||
// Sort characters
|
||||
characters := arn.FilterCharacters(func(character *arn.Character) bool {
|
||||
return !character.IsDraft
|
||||
})
|
||||
|
||||
arn.SortCharactersByLikes(characters)
|
||||
|
||||
// Allow CORS
|
||||
ctx.Response().Header().Set("Access-Control-Allow-Origin", "*")
|
||||
|
||||
// Return ranking
|
||||
for index, character := range characters {
|
||||
if character.ID == id {
|
||||
return strconv.Itoa(index + 1)
|
||||
}
|
||||
}
|
||||
|
||||
// If the ID wasn't found for some reason,
|
||||
// return an empty string.
|
||||
return ""
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user