1
0
mirror of https://github.com/mxpv/podsync.git synced 2024-05-11 05:55:04 +00:00

Implement static files handling

This commit is contained in:
Maksym Pavlenko
2017-08-19 22:04:41 -07:00
parent 6b0a234983
commit c8d5a2000d
3 changed files with 23 additions and 0 deletions

View File

@@ -34,6 +34,7 @@ func ReadConfiguration() (cfg *AppConfig, err error) {
"patreonClientId": "PATREON_CLIENT_ID",
"patreonSecret": "PATREON_SECRET",
"postgresConnectionUrl": "POSTGRES_CONNECTION_URL",
"redisUrl": "REDIS_CONNECTION_URL",
}
for k, v := range envmap {

View File

@@ -2,7 +2,10 @@ package server
import (
"context"
"go/build"
"log"
"net/http"
"path"
"github.com/gin-gonic/gin"
itunes "github.com/mxpv/podcast"
@@ -20,6 +23,20 @@ func MakeHandlers(feed feed) http.Handler {
r := gin.New()
r.Use(gin.Recovery())
// Static files + HTML
rootDir := path.Join(build.Default.GOPATH, "src/github.com/mxpv/podsync")
log.Printf("Using root directory: %s", rootDir)
r.Static("/assets", path.Join(rootDir, "assets"))
r.LoadHTMLGlob(path.Join(rootDir, "templates/*.html"))
r.GET("/", func(c *gin.Context) {
c.HTML(http.StatusOK, "index.html", gin.H{"title": "Index page"})
})
// REST API
r.GET("/ping", func(c *gin.Context) {
c.String(http.StatusOK, "ok")
})

5
templates/index.html Normal file
View File

@@ -0,0 +1,5 @@
<html>
<h1>
{{ .title }}
</h1>
</html>