Skip to content

Commit bd52ece

Browse files
committed
Add vibe relay for serving up third party static content
1 parent 1e2a5ab commit bd52ece

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

web/server.go

+25
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,10 @@ import (
1414
"goirc/internal/summary"
1515
db "goirc/model"
1616
"html/template"
17+
"io"
1718
"log"
1819
"net/http"
20+
"net/url"
1921
"os"
2022
"strconv"
2123
"strings"
@@ -250,6 +252,29 @@ func Serve(db *sqlx.DB, b *bot.Bot) {
250252
http.Redirect(w, r, note.Text.String, http.StatusSeeOther)
251253
})
252254

255+
r.Get("/vibe", func(w http.ResponseWriter, r *http.Request) {
256+
contentURL := r.FormValue("url")
257+
258+
parsedURL, err := url.Parse(contentURL)
259+
if parsedURL.Host != "gist.githubusercontent.com" {
260+
http.Error(w, "host not allowed", http.StatusBadRequest)
261+
return
262+
}
263+
264+
resp, err := http.Get(parsedURL.String())
265+
if err != nil {
266+
http.Error(w, err.Error(), http.StatusInternalServerError)
267+
return
268+
}
269+
defer resp.Body.Close()
270+
bytes, err := io.ReadAll(resp.Body)
271+
if err != nil {
272+
http.Error(w, err.Error(), http.StatusInternalServerError)
273+
return
274+
}
275+
w.Write(bytes)
276+
})
277+
253278
r.Group(func(r chi.Router) {
254279
r.Use(func(next http.Handler) http.Handler {
255280
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {

0 commit comments

Comments
 (0)