diff --git a/audon-fe/index.html b/audon-fe/index.html index 40fbc44..4abde0f 100644 --- a/audon-fe/index.html +++ b/audon-fe/index.html @@ -1,13 +1,47 @@ +{% define "tmpl" %} - + + Audon + + + + + + {% if .Room %} + + {% if .Room.Description %} + + {% else %} + + {% end %} + {% else %} + + + {% end %} + + + + + {% if .Room %} + + {% if .Room.Description %} + + {% else %} + + {% end %} + {% else %} + + + {% end %}
+{% end %} \ No newline at end of file diff --git a/audon-fe/public/static/opengraph.c05d412c.png b/audon-fe/public/static/opengraph.c05d412c.png new file mode 100644 index 0000000..244047a Binary files /dev/null and b/audon-fe/public/static/opengraph.c05d412c.png differ diff --git a/audon-fe/src/App.vue b/audon-fe/src/App.vue index f6f5e12..3bda4f8 100644 --- a/audon-fe/src/App.vue +++ b/audon-fe/src/App.vue @@ -23,7 +23,10 @@ export default { \ No newline at end of file diff --git a/room.go b/room.go index 9395686..69f40d5 100644 --- a/room.go +++ b/room.go @@ -152,6 +152,22 @@ func updateRoomHandler(c echo.Context) (err error) { return c.JSON(http.StatusOK, room) } +// handler for GET to /r/:id +func renderRoomHandler(c echo.Context) error { + roomID := c.Param("id") + if err := mainValidator.Var(&roomID, "required,printascii"); err != nil { + return wrapValidationError(err) + } + + room, err := findRoomByID(c.Request().Context(), roomID) + if err != nil { + return echo.NotFoundHandler(c) + } + + return c.Render(http.StatusOK, "tmpl", &TemplateData{Config: &mainConfig.AppConfigBase, Room: room}) +} + +// for preview, this bypasses authentication func previewRoomHandler(c echo.Context) (err error) { roomID := c.Param("id") if err := mainValidator.Var(&roomID, "required,printascii"); err != nil { diff --git a/server.go b/server.go index 1b467b2..05fc92b 100644 --- a/server.go +++ b/server.go @@ -32,6 +32,11 @@ type ( templates *template.Template } + TemplateData struct { + Config *AppConfigBase + Room *Room + } + CustomValidator struct { validator *validator.Validate } @@ -100,6 +105,9 @@ func main() { defer e.Close() e.Validator = &CustomValidator{validator: mainValidator} + e.Renderer = &Template{ + templates: template.Must(template.New("tmpl").Delims("{%", "%}").ParseGlob("audon-fe/dist/index.html")), + } // Setup session middleware (currently Audon stores all client data in cookie) log.Println("Connecting to Redis") @@ -151,7 +159,12 @@ func main() { api.PUT("/room/:room/:user", updatePermissionHandler) e.Static("/assets", "audon-fe/dist/assets") - e.File("/*", "audon-fe/dist/index.html") + e.Static("/static", "audon-fe/dist/static") + e.GET("/r/:id", renderRoomHandler) + e.GET("/*", func(c echo.Context) error { + return c.Render(http.StatusOK, "tmpl", &TemplateData{Config: &mainConfig.AppConfigBase}) + }) + // e.File("/*", "audon-fe/dist/index.html") // use anonymous func to support graceful shutdown go func() {