1
0
mirror of https://github.com/schollz/cowyo.git synced 2023-08-10 21:13:00 +03:00

Add default page Fixes #91

This commit is contained in:
Zack Scholl 2017-11-04 04:21:51 -06:00
parent 2040dbaaa5
commit d481145c5f
2 changed files with 12 additions and 3 deletions

View File

@ -19,7 +19,7 @@ import (
var customCSS []byte var customCSS []byte
func serve(host, port, crt_path, key_path string, TLS bool, cssFile string) { func serve(host, port, crt_path, key_path string, TLS bool, cssFile string, defaultPage string) {
gin.SetMode(gin.ReleaseMode) gin.SetMode(gin.ReleaseMode)
router := gin.Default() router := gin.Default()
store := sessions.NewCookieStore([]byte("secret")) store := sessions.NewCookieStore([]byte("secret"))
@ -27,7 +27,11 @@ func serve(host, port, crt_path, key_path string, TLS bool, cssFile string) {
router.HTMLRender = loadTemplates("index.tmpl") router.HTMLRender = loadTemplates("index.tmpl")
// router.Use(static.Serve("/static/", static.LocalFile("./static", true))) // router.Use(static.Serve("/static/", static.LocalFile("./static", true)))
router.GET("/", func(c *gin.Context) { router.GET("/", func(c *gin.Context) {
if defaultPage != "" {
c.Redirect(302, "/"+defaultPage+"/read")
} else {
c.Redirect(302, "/"+randomAlliterateCombo()) c.Redirect(302, "/"+randomAlliterateCombo())
}
}) })
router.GET("/:page", func(c *gin.Context) { router.GET("/:page", func(c *gin.Context) {
page := c.Param("page") page := c.Param("page")

View File

@ -38,7 +38,7 @@ func main() {
} else { } else {
fmt.Printf("\nRunning cowyo server (version %s) at http://%s:%s\n\n", version, host, c.GlobalString("port")) fmt.Printf("\nRunning cowyo server (version %s) at http://%s:%s\n\n", version, host, c.GlobalString("port"))
} }
serve(c.GlobalString("host"), c.GlobalString("port"), c.GlobalString("cert"), c.GlobalString("key"), TLS, c.GlobalString("css")) serve(c.GlobalString("host"), c.GlobalString("port"), c.GlobalString("cert"), c.GlobalString("key"), TLS, c.GlobalString("css"), c.GlobalString("default-page"))
return nil return nil
} }
app.Flags = []cli.Flag{ app.Flags = []cli.Flag{
@ -77,6 +77,11 @@ func main() {
Value: "", Value: "",
Usage: "use a custom CSS file", Usage: "use a custom CSS file",
}, },
cli.StringFlag{
Name: "default-page",
Value: "",
Usage: "show default-page/read instead of editing",
},
cli.BoolFlag{ cli.BoolFlag{
Name: "debug, d", Name: "debug, d",
Usage: "turn on debugging", Usage: "turn on debugging",