mirror of
https://github.com/ultrasn0w/huso.git
synced 2025-12-13 14:09:52 +01:00
Local server flag
This commit is contained in:
1
huso.go
1
huso.go
@@ -36,6 +36,7 @@ var (
|
||||
malApiBaseUri = flag.String("malApiBaseUri", "https://api.myanimelist.net/v2/", "MyAnimeList API base URL")
|
||||
jikanApiBaseUri = flag.String("jikanApiBaseUri", "https://api.jikan.moe/v4/", "Jikan API base URL")
|
||||
malApiId = flag.String("malApiId", "cc17dcf40581b9dfc8a5a12dba458153", "MyAnimeList API Client ID")
|
||||
localServer = flag.Bool("localServer", false, "Set varius headers for running locally")
|
||||
cache *bigcache.BigCache
|
||||
animeCache *bigcache.BigCache
|
||||
db *nutsdb.DB
|
||||
|
||||
34
ober.go
34
ober.go
@@ -14,14 +14,14 @@ import (
|
||||
|
||||
func RunWebserv() {
|
||||
r := router.New()
|
||||
r.GET("/", Start)
|
||||
r.GET("/api/season", Season)
|
||||
r.GET("/api/anime/{id}", AnimeGet)
|
||||
r.GET("/api/watch/{user?}", WatchGet)
|
||||
r.POST("/api/register", Register)
|
||||
r.POST("/api/watch/{user}", WatchPost)
|
||||
r.DELETE("/api/register", UnRegister)
|
||||
r.DELETE("/api/watch/{user}", WatchDelete)
|
||||
r.GET("/", Headers(Start))
|
||||
r.GET("/api/season", Headers(Season))
|
||||
r.GET("/api/anime/{id}", Headers(AnimeGet))
|
||||
r.GET("/api/watch/{user?}", Headers(WatchGet))
|
||||
r.POST("/api/register", Headers(Register))
|
||||
r.POST("/api/watch/{user}", Headers(WatchPost))
|
||||
r.DELETE("/api/register", Headers(UnRegister))
|
||||
r.DELETE("/api/watch/{user}", Headers(WatchDelete))
|
||||
log.Fatal(fasthttp.ListenAndServe(":"+strconv.Itoa(*webServerPort), r.Handler))
|
||||
}
|
||||
|
||||
@@ -50,6 +50,9 @@ func Season(ctx *fasthttp.RequestCtx) {
|
||||
addErrorToCtx(ctx, err)
|
||||
return
|
||||
}
|
||||
|
||||
ctx.SetContentType("application/json; charset=utf-8")
|
||||
ctx.SetStatusCode(fasthttp.StatusOK)
|
||||
}
|
||||
|
||||
func AnimeGet(ctx *fasthttp.RequestCtx) {
|
||||
@@ -86,6 +89,7 @@ func AnimeGet(ctx *fasthttp.RequestCtx) {
|
||||
addErrorToCtx(ctx, err)
|
||||
return
|
||||
}
|
||||
|
||||
ctx.SetContentType("application/json; charset=utf-8")
|
||||
ctx.SetStatusCode(fasthttp.StatusOK)
|
||||
}
|
||||
@@ -198,6 +202,7 @@ func Register(ctx *fasthttp.RequestCtx) {
|
||||
}
|
||||
|
||||
ctx.SetBody(body)
|
||||
ctx.SetContentType("application/json; charset=utf-8")
|
||||
ctx.SetStatusCode(fasthttp.StatusOK)
|
||||
}
|
||||
|
||||
@@ -244,6 +249,7 @@ func UnRegister(ctx *fasthttp.RequestCtx) {
|
||||
}
|
||||
|
||||
ctx.SetBody(body)
|
||||
ctx.SetContentType("application/json; charset=utf-8")
|
||||
ctx.SetStatusCode(fasthttp.StatusOK)
|
||||
}
|
||||
|
||||
@@ -313,6 +319,7 @@ func processUpdateReq(ctx *fasthttp.RequestCtx, update bool) {
|
||||
addErrorToCtx(ctx, err)
|
||||
return
|
||||
}
|
||||
ctx.SetContentType("application/json; charset=utf-8")
|
||||
}
|
||||
|
||||
func GheddoAuth(username, auth string) (bool, int64) {
|
||||
@@ -323,6 +330,17 @@ func GheddoAuth(username, auth string) (bool, int64) {
|
||||
return user.Secret == auth, user.MalID
|
||||
}
|
||||
|
||||
func Headers(h fasthttp.RequestHandler) fasthttp.RequestHandler {
|
||||
return fasthttp.RequestHandler(func(ctx *fasthttp.RequestCtx) {
|
||||
if *localServer {
|
||||
ctx.Response.Header.Set("Access-Control-Allow-Origin", "*")
|
||||
ctx.Response.Header.Set("Access-Control-Allow-Headers", "*")
|
||||
ctx.Response.Header.Set("Access-Control-Allow-Methods", "*")
|
||||
}
|
||||
h(ctx)
|
||||
})
|
||||
}
|
||||
|
||||
func writeResponseBody(ctx *fasthttp.RequestCtx, bytes []byte) error {
|
||||
_, err := ctx.Write(bytes)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user