aboutsummaryrefslogtreecommitdiff
path: root/backend/main.go
blob: 1ca18df895e8a91bdabd72043bd5298dcd34c68a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package main

import (
	"encoding/json"
	"llostre/backend/fetchers"
	"net/http"
)

func postsHandler(w http.ResponseWriter, r *http.Request) {
	w.Header().Set("Access-Control-Allow-Origin", "*")
	w.Header().Set("Content-Type", "application/json")

	// wip
	did := "did:plc:hyyqbqqhpxt2bnn7s2e2iuxd"
	pdsURL := "https://bsky.vylion.com"

	posts, err := fetchers.FetchAppBskyFeedPosts(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("/api/posts", postsHandler)
	http.ListenAndServe(":8080", nil)
}