An experimental IndieWeb site built in Go.
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

add CORS support for Micropub

+10 -48
+1
go.mod
··· 18 18 github.com/cespare/xxhash/v2 v2.3.0 // indirect 19 19 github.com/dustin/go-humanize v1.0.1 // indirect 20 20 github.com/glebarez/go-sqlite v1.21.2 // indirect 21 + github.com/go-chi/cors v1.2.1 // indirect 21 22 github.com/go-sql-driver/mysql v1.8.1 // indirect 22 23 github.com/google/uuid v1.3.0 // indirect 23 24 github.com/jinzhu/inflection v1.0.0 // indirect
+2
go.sum
··· 19 19 github.com/glebarez/sqlite v1.11.0/go.mod h1:h8/o8j5wiAsqSPoWELDUdJXhjAhsVliSn7bWZjOhrgQ= 20 20 github.com/go-chi/chi/v5 v5.1.0 h1:acVI1TYaD+hhedDJ3r54HyA6sExp3HfXq7QWEEY/xMw= 21 21 github.com/go-chi/chi/v5 v5.1.0/go.mod h1:DslCQbL2OYiznFReuXYUmQ2hGd1aDpCnlMNITLSKoi8= 22 + github.com/go-chi/cors v1.2.1 h1:xEC8UT3Rlp2QuWNEr4Fs/c2EAGVKBwy/1vHx3bppil4= 23 + github.com/go-chi/cors v1.2.1/go.mod h1:sSbTewc+6wYHBBCW7ytsFSn836hqM7JxpglAy2Vzc58= 22 24 github.com/go-chi/httprate v0.12.0 h1:08D/te3pOTJe5+VAZTQrHxwdsH2NyliiUoRD1naKaMg= 23 25 github.com/go-chi/httprate v0.12.0/go.mod h1:TUepLXaz/pCjmCtf/obgOQJ2Sz6rC8fSf5cAt5cnTt0= 24 26 github.com/go-sql-driver/mysql v1.7.0/go.mod h1:OXbVy3sEdcQ2Doequ6Z5BW6fXNQTmx+9S1MCJN5yJMI=
+7 -48
main.go
··· 16 16 "github.com/a-h/templ" 17 17 "github.com/go-chi/chi/v5" 18 18 "github.com/go-chi/chi/v5/middleware" 19 + "github.com/go-chi/cors" 19 20 "github.com/go-chi/httprate" 20 21 21 22 "go.hacdias.com/indielib/indieauth" ··· 88 89 89 90 // Micropub handler 90 91 r.Route("/micropub", func(r chi.Router) { 92 + // Enable CORS for browser-based clients 93 + r.Use(cors.Handler( 94 + cors.Options{ 95 + AllowedHeaders: []string{"Accept", "Authorization", "Content-Type"}, 96 + }, 97 + )) 91 98 r.Use(s.mustAuth) 92 99 r.Get("/", s.serveMicropub) 93 100 r.Post("/", s.serveMicropub) ··· 108 115 } 109 116 110 117 func (s *server) serveHomeTemplate(w http.ResponseWriter, r *http.Request) { 111 - // q := query.NewQuery( 112 - // string(db.PostCollection), 113 - // ).Sort(query.SortOption{ 114 - // Field: "createdAt", 115 - // Direction: -1, 116 - // }).Limit(10) 117 - 118 - // docs, err := s.db.Docs.FindAll(q) 119 - // if err != nil { 120 - // httpError(w, http.StatusInternalServerError) 121 - // panic(err) 122 - // } 123 - 124 118 posts := make([]*models.Post, 0) 125 119 result := s.db.Db.Limit(10).Find(&posts) 126 120 if result.Error != nil { 127 121 panic(result.Error) 128 122 } 129 123 130 - // posts := make([]*models.Post, len(docs)) 131 - // for i, doc := range docs { 132 - // id := doc.ObjectId() 133 - // post := &models.Post{ 134 - // ID: id, 135 - // } 136 - 137 - // if err := doc.Unmarshal(post); err != nil { 138 - // httpError(w, http.StatusInternalServerError) 139 - // panic(err) 140 - // } 141 - 142 - // post.ID = id 143 - 144 - // posts[i] = post 145 - // } 146 - 147 124 templ.Handler(pages.Home(s.profileURL, posts)).ServeHTTP(w, r) 148 125 } 149 126 ··· 151 128 id := chi.URLParam(r, "slug") 152 129 post := &models.Post{} 153 130 154 - // doc, err := s.db.Docs.FindById(string(db.PostCollection), id) 155 - // if err != nil { 156 - // httpError(w, http.StatusInternalServerError) 157 - // return 158 - // } else if doc == nil { 159 - // httpError(w, http.StatusNotFound) 160 - // return 161 - // } 162 - 163 - // postUlid, err := ulid.ParseString(id) 164 - // if err != nil { 165 - // panic(err) 166 - // } 167 131 result := s.db.Db.First(post, "id = ?", id) 168 132 169 133 if result.RowsAffected == 0 { 170 134 httpError(w, http.StatusNotFound) 171 135 return 172 136 } 173 - 174 - // if err := doc.Unmarshal(post); err != nil { 175 - // httpError(w, http.StatusInternalServerError) 176 - // return 177 - // } 178 137 179 138 templ.Handler(pages.Post(post)).ServeHTTP(w, r) 180 139 }