Skip to content

Commit 7bf0eae

Browse files
committed
respect X-Forwarded-Proto when generated urls, improve reddit post links
1 parent f1c8a8d commit 7bf0eae

File tree

6 files changed

+26
-7
lines changed

6 files changed

+26
-7
lines changed

main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,10 @@ func main() {
6161
e.GET("/activity.json", server.ActivityHandler(db))
6262
e.GET("/rss", server.RSSHandler(db))
6363
e.GET("/rss.php", func(c echo.Context) error {
64-
return c.Redirect(http.StatusMovedPermanently, fmt.Sprintf("%v://%v/rss", c.Scheme(), c.Request().Host))
64+
return c.Redirect(http.StatusMovedPermanently, server.AbsoluteURL(c, "/rss"))
6565
})
6666
e.File("/favicon.ico", path.Join(viper.GetString("staticdir"), "favicon.ico"))
6767
e.Static("/static", viper.GetString("staticdir"))
6868

69-
log.Fatal(e.Start(fmt.Sprintf(":%v", viper.GetString("port"))))
69+
log.Fatal(e.Start(fmt.Sprintf(":%v", viper.GetInt("port"))))
7070
}

server/common.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package server
2+
3+
import (
4+
"github.com/labstack/echo"
5+
)
6+
7+
func AbsoluteURL(c echo.Context, resource string) string {
8+
if len(resource) > 0 && resource[0] != '/' {
9+
resource = "/" + resource
10+
}
11+
scheme := c.Scheme()
12+
if c.Request().Header.Get(echo.HeaderXForwardedProto) == "https" {
13+
scheme = "https"
14+
}
15+
return scheme + "://" + c.Request().Host + resource
16+
}

server/index_handler.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ var index = `<!DOCTYPE html><html>
6363
</footer>
6464
</div>
6565
66-
<script src="static/index.js"></script>
66+
<script src="static/index.js?v1"></script>
6767
</body>
6868
</html>`
6969

server/reddit_indexer.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ func (indexer *RedditIndexer) redditActivity(user string, page string) ([]Activi
126126
if err != nil {
127127
return nil, "", err
128128
}
129-
req.Header.Add("User-Agent", "GGGTracker (gggtracker.com) by /u/rz2yoj")
129+
req.Header.Add("User-Agent", "GGG Tracker (https://github.com/ccbrown/gggtracker) by /u/rz2yoj")
130130

131131
resp, err := client.Do(req)
132132
if err != nil {

server/rss_handler.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ func RSSHandler(db *Database) echo.HandlerFunc {
3636
Channel: rssChannel{
3737
Title: "GGG Tracker",
3838
Description: "Latest activity from Grinding Gear Games",
39-
Link: fmt.Sprintf("%v://%v", c.Scheme(), c.Request().Host),
39+
Link: AbsoluteURL(c, ""),
4040
},
4141
}
4242
for _, a := range activity {

server/static/index.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,10 @@ function loadActivity() {
3131
.append($('<img src="static/images/snoo.png" />'))
3232
));
3333
} else {
34-
$tr.append($('<td class="icon">').append($('<img src="static/images/snoo.png" />')));
34+
$tr.append($('<td class="icon">').append($('<a>')
35+
.attr('href', 'https://www.reddit.com' + activity.permalink)
36+
.append($('<img src="static/images/snoo.png" />'))
37+
));
3538
}
3639

3740
if (type == 'forum_post') {
@@ -41,7 +44,7 @@ function loadActivity() {
4144
));
4245
} else if (type == "reddit_post") {
4346
$tr.append($('<td class="title">').append($('<a>')
44-
.attr('href', 'https://www.reddit.com' + activity.permalink)
47+
.attr('href', activity.url ? activity.url : ('https://www.reddit.com/r/pathofexile/comments/' + activity.post_id))
4548
.text(activity.title)
4649
));
4750
} else if (type == "reddit_comment") {

0 commit comments

Comments
 (0)