Skip to content

Commit 57b4483

Browse files
committed
Redirect asset requests to cdn.rawgit.com
This allows users to serve custom assets from their repositories. Closes #21 Closes #34
1 parent d812b7e commit 57b4483

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

viewdocs.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,25 @@ func fetchAndRenderDoc(user, repo, ref, doc string) (string, error) {
194194
return output, nil
195195
}
196196

197+
func isAsset(name string) bool {
198+
assetExts := map[string]bool{
199+
".appcache": true,
200+
".bmp": true,
201+
".css": true,
202+
".jpg": true,
203+
".jpeg": true,
204+
".js": true,
205+
".json": true,
206+
".png": true,
207+
}
208+
209+
if ok, _ := assetExts[path.Ext(name)]; ok {
210+
return true
211+
}
212+
213+
return false
214+
}
215+
197216
func main() {
198217
if os.Getenv("ACCESS_TOKEN") == "" {
199218
// TODO: Add direct link to Development section of the README
@@ -229,6 +248,13 @@ func main() {
229248
switch r.Method {
230249
case "GET":
231250
user, repo, ref, doc := parseRequest(r)
251+
252+
if isAsset(doc) {
253+
assetUrl := "https://cdn.rawgit.com/" + user + "/" + repo + "/" + ref + "/docs/" + doc
254+
http.Redirect(w, r, assetUrl, 301)
255+
return
256+
}
257+
232258
log.Printf("Building docs for '%s/%s' (ref: %s)", user, repo, ref)
233259
key := user + ":" + repo + ":" + doc + ":" + ref
234260
value, ok := lru.Get(key)

0 commit comments

Comments
 (0)