diff options
| -rw-r--r-- | backend/main.go | 33 |
1 files changed, 21 insertions, 12 deletions
diff --git a/backend/main.go b/backend/main.go index 429dd37..24a2973 100644 --- a/backend/main.go +++ b/backend/main.go @@ -1,26 +1,35 @@ package main import ( - "fmt" - "io" + "encoding/json" + "llostre/backend/fetchers" "net/http" ) -func helloHandler(w http.ResponseWriter, _ *http.Request) { +func postsHandler(w http.ResponseWriter, r *http.Request) { w.Header().Set("Access-Control-Allow-Origin", "*") w.Header().Set("Content-Type", "application/json") - w.Write([]byte("Hello, World!")) -} -func requestServer() { - resp, err := http.Get("http://localhost:8080") - fmt.Println(err) - defer resp.Body.Close() - body, err := io.ReadAll(resp.Body) - fmt.Printf("\nWebserver said: `%s`", string(body)) + // wip + did := "did:plc:hyyqbqqhpxt2bnn7s2e2iuxd" + pdsURL := "https://bsky.vylion.com" + + posts, err := fetchers.FetchBlueskyPosts(did, pdsURL) + if err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } + + jsonData, err := json.Marshal(posts) + if err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } + + w.Write(jsonData) } func main() { - http.HandleFunc("/", helloHandler) + http.HandleFunc("/api/posts", postsHandler) http.ListenAndServe(":8080", nil) } |
