Compare commits

...

5 Commits

Author SHA1 Message Date
b3fe5c17ed
Merge branch 'missing-files' into new-microsub-package
All checks were successful
the build was successful
2018-09-15 15:57:05 +02:00
ec8da2692c
Add missing files 2018-09-15 15:55:27 +02:00
8607a27150
Move the OutputContentType outside 2018-09-15 15:53:10 +02:00
46b8f2a315
Changes in the README 2018-09-15 15:52:52 +02:00
a7f19759df
Add utf-8 to content-type
All checks were successful
the build was successful
2018-09-15 10:51:27 +02:00
2 changed files with 21 additions and 18 deletions

View File

@ -1,11 +1,6 @@
# ekster # ekster
a microsub server a [Microsub](https://indieweb.org/Microsub) server
## Warning!
Very alpha: no warranty.
## Installing and running ekster ## Installing and running ekster
@ -19,7 +14,7 @@ you need a Go environment. Use these commands to install the programs.
go get -u p83.nl/go/ekster/cmd/eksterd go get -u p83.nl/go/ekster/cmd/eksterd
go get -u p83.nl/go/ekster/cmd/ek go get -u p83.nl/go/ekster/cmd/ek
`eksterd` uses [Redis](https://redis.io/) as the database, to temporarily save `eksterd` uses [Redis](https://redis.io/) as the database to temporarily save
the items and feeds. The more permanent information is saved in `backend.json`. the items and feeds. The more permanent information is saved in `backend.json`.
#### Running eksterd #### Running eksterd
@ -162,3 +157,7 @@ Micropub client.
`ekster` will check every 10 minutes, if the token is still valid. This could `ekster` will check every 10 minutes, if the token is still valid. This could
be retrieved automatically, but this doesn't happen at the moment. be retrieved automatically, but this doesn't happen at the moment.
## Other Microsub projects
* <https://indieweb.org/Microsub>
* Aperture: [code](https://github.com/aaronparecki/Aperture), [hosted](https://aperture.p3k.io)

View File

@ -31,6 +31,10 @@ var (
entryRegex = regexp.MustCompile("^entry\\[\\d+\\]$") entryRegex = regexp.MustCompile("^entry\\[\\d+\\]$")
) )
const (
OutputContentType = "application/json; charset=utf-8"
)
type microsubHandler struct { type microsubHandler struct {
backend microsub.Microsub backend microsub.Microsub
} }
@ -63,7 +67,7 @@ func (h *microsubHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
return return
} }
jw := json.NewEncoder(w) jw := json.NewEncoder(w)
w.Header().Add("Content-Type", "application/json") w.Header().Add("Content-Type", OutputContentType)
err = jw.Encode(map[string][]microsub.Channel{ err = jw.Encode(map[string][]microsub.Channel{
"channels": channels, "channels": channels,
}) })
@ -78,7 +82,7 @@ func (h *microsubHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
return return
} }
jw := json.NewEncoder(w) jw := json.NewEncoder(w)
w.Header().Add("Content-Type", "application/json") w.Header().Add("Content-Type", OutputContentType)
jw.SetIndent("", " ") jw.SetIndent("", " ")
jw.SetEscapeHTML(false) jw.SetEscapeHTML(false)
err = jw.Encode(timeline) err = jw.Encode(timeline)
@ -94,7 +98,7 @@ func (h *microsubHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
} }
jw := json.NewEncoder(w) jw := json.NewEncoder(w)
jw.SetIndent("", " ") jw.SetIndent("", " ")
w.Header().Add("Content-Type", "application/json") w.Header().Add("Content-Type", OutputContentType)
err = jw.Encode(timeline) err = jw.Encode(timeline)
if err != nil { if err != nil {
http.Error(w, err.Error(), 500) http.Error(w, err.Error(), 500)
@ -108,7 +112,7 @@ func (h *microsubHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
return return
} }
jw := json.NewEncoder(w) jw := json.NewEncoder(w)
w.Header().Add("Content-Type", "application/json") w.Header().Add("Content-Type", OutputContentType)
err = jw.Encode(map[string][]microsub.Feed{ err = jw.Encode(map[string][]microsub.Feed{
"items": following, "items": following,
}) })
@ -140,7 +144,7 @@ func (h *microsubHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
http.Error(w, err.Error(), 500) http.Error(w, err.Error(), 500)
return return
} }
w.Header().Add("Content-Type", "application/json") w.Header().Add("Content-Type", OutputContentType)
fmt.Fprintln(w, "[]") fmt.Fprintln(w, "[]")
return return
} }
@ -152,7 +156,7 @@ func (h *microsubHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
http.Error(w, err.Error(), 500) http.Error(w, err.Error(), 500)
return return
} }
w.Header().Add("Content-Type", "application/json") w.Header().Add("Content-Type", OutputContentType)
err = jw.Encode(channel) err = jw.Encode(channel)
if err != nil { if err != nil {
http.Error(w, err.Error(), 500) http.Error(w, err.Error(), 500)
@ -164,7 +168,7 @@ func (h *microsubHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
http.Error(w, err.Error(), 500) http.Error(w, err.Error(), 500)
return return
} }
w.Header().Add("Content-Type", "application/json") w.Header().Add("Content-Type", OutputContentType)
err = jw.Encode(channel) err = jw.Encode(channel)
if err != nil { if err != nil {
http.Error(w, err.Error(), 500) http.Error(w, err.Error(), 500)
@ -180,7 +184,7 @@ func (h *microsubHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
http.Error(w, err.Error(), 500) http.Error(w, err.Error(), 500)
return return
} }
w.Header().Add("Content-Type", "application/json") w.Header().Add("Content-Type", OutputContentType)
jw := json.NewEncoder(w) jw := json.NewEncoder(w)
err = jw.Encode(feed) err = jw.Encode(feed)
if err != nil { if err != nil {
@ -195,7 +199,7 @@ func (h *microsubHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
http.Error(w, err.Error(), 500) http.Error(w, err.Error(), 500)
return return
} }
w.Header().Add("Content-Type", "application/json") w.Header().Add("Content-Type", OutputContentType)
fmt.Fprintln(w, "[]") fmt.Fprintln(w, "[]")
} else if action == "search" { } else if action == "search" {
query := values.Get("query") query := values.Get("query")
@ -205,7 +209,7 @@ func (h *microsubHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
return return
} }
jw := json.NewEncoder(w) jw := json.NewEncoder(w)
w.Header().Add("Content-Type", "application/json") w.Header().Add("Content-Type", OutputContentType)
err = jw.Encode(map[string][]microsub.Feed{ err = jw.Encode(map[string][]microsub.Feed{
"results": feeds, "results": feeds,
}) })
@ -245,7 +249,7 @@ func (h *microsubHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
http.Error(w, fmt.Sprintf("unknown method in timeline %s\n", method), 500) http.Error(w, fmt.Sprintf("unknown method in timeline %s\n", method), 500)
return return
} }
w.Header().Add("Content-Type", "application/json") w.Header().Add("Content-Type", OutputContentType)
fmt.Fprintln(w, "[]") fmt.Fprintln(w, "[]")
} else { } else {
http.Error(w, fmt.Sprintf("unknown action %s\n", action), 500) http.Error(w, fmt.Sprintf("unknown action %s\n", action), 500)