Skip to content

Commit

Permalink
add favicon middleware
Browse files Browse the repository at this point in the history
  • Loading branch information
negrel committed Jan 16, 2024
1 parent f96b6c2 commit 0bd0a83
Show file tree
Hide file tree
Showing 18 changed files with 99 additions and 5 deletions.
3 changes: 3 additions & 0 deletions cmd/server/fiber.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ func ProvideFiber(
requestIdMiddleware middlewares.RequestId,
staticMiddleware middlewares.Static,
withSessionMiddleware middlewares.WithSession,
faviconMiddleware middlewares.Favicon,
getSignUpHandler handlers.GetSignUp,
postSignUpHander handlers.PostSignUp,
getSignInHandler handlers.GetSignIn,
Expand Down Expand Up @@ -50,6 +51,8 @@ func ProvideFiber(
app.Use(fiber.Handler(loggerMiddleware))

// Public endpoints.
app.Use(fiber.Handler(faviconMiddleware))

app.Use("/static", fiber.Handler(staticMiddleware))

app.Get("/sign_up", fiber.Handler(getSignUpHandler))
Expand Down
1 change: 1 addition & 0 deletions cmd/server/wire.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ func initialize(logger BootstrapLogger) App {
middlewares.ProvideAccessLog,
middlewares.ProvideLogger,
middlewares.ProvideWithSession,
middlewares.ProvideFavicon,
handlers.ProvideGetSignUp,
handlers.ProvidePostSignUp,
handlers.ProvideGetSignIn,
Expand Down
3 changes: 2 additions & 1 deletion cmd/server/wire_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added internal/embedded/static/apple-touch-icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 9 additions & 0 deletions internal/embedded/static/browserconfig.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<browserconfig>
<msapplication>
<tile>
<square150x150logo src="/static/mstile-150x150.png"/>
<TileColor>#da532c</TileColor>
</tile>
</msapplication>
</browserconfig>
Binary file added internal/embedded/static/favicon-16x16.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added internal/embedded/static/favicon-32x32.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added internal/embedded/static/favicon.ico
Binary file not shown.
Binary file added internal/embedded/static/mstile-150x150.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
33 changes: 33 additions & 0 deletions internal/embedded/static/safari-pinned-tab.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19 changes: 19 additions & 0 deletions internal/embedded/static/site.webmanifest
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"name": "",
"short_name": "",
"icons": [
{
"src": "/static/android-chrome-192x192.png",
"sizes": "192x192",
"type": "image/png"
},
{
"src": "/static/android-chrome-512x512.png",
"sizes": "512x512",
"type": "image/png"
}
],
"theme_color": "#ffffff",
"background_color": "#ffffff",
"display": "standalone"
}
9 changes: 9 additions & 0 deletions internal/embedded/views/partials/favicon.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<link rel="apple-touch-icon" sizes="180x180" href="/static/apple-touch-icon.png">
<link rel="icon" type="image/png" sizes="32x32" href="/static/favicon-32x32.png">
<link rel="icon" type="image/png" sizes="16x16" href="/static/favicon-16x16.png">
<link rel="manifest" href="/static/site.webmanifest">
<link rel="mask-icon" href="/static/safari-pinned-tab.svg" color="#5bbad5">
<link rel="shortcut icon" href="/static/favicon.ico">
<meta name="msapplication-TileColor" content="#da532c">
<meta name="msapplication-config" content="/static/browserconfig.xml">
<meta name="theme-color" content="#ffffff">
5 changes: 1 addition & 4 deletions internal/embedded/views/partials/head.html
Original file line number Diff line number Diff line change
@@ -1,4 +1 @@
<head>
<title>{{ template "title" }}</title>
{{ template "css" }}
</head>
{{- template "partials/favicon" -}}
1 change: 1 addition & 0 deletions internal/embedded/views/sign_in.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

<head>
<title>Sign In - Prisme Analytics</title>
{{ template "partials/head" }}
{{ template "partials/tailwindcss" }}
</head>

Expand Down
1 change: 1 addition & 0 deletions internal/embedded/views/sign_up.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

<head>
<title>Sign Up - Prisme Analytics</title>
{{ template "partials/head" }}
{{ template "partials/tailwindcss" }}
</head>

Expand Down
20 changes: 20 additions & 0 deletions internal/middlewares/favicon.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package middlewares

import (
"net/http"

"github.com/gofiber/fiber/v2"
"github.com/gofiber/fiber/v2/middleware/favicon"
"github.com/prismelabs/prismeanalytics/internal/embedded"
)

type Favicon fiber.Handler

// ProvideFavicon is a wire provider for in memory favicon middleware.
func ProvideFavicon() Favicon {
return favicon.New(favicon.Config{
File: "static/favicon.ico",
URL: "",
FileSystem: http.FS(embedded.Static),
})
}

0 comments on commit 0bd0a83

Please sign in to comment.