Reorganize public folder to better handle static assets, no-cache index

This commit is contained in:
zikaeroh 2020-05-24 12:50:05 -07:00
parent ec12d4f3e7
commit da2036a551
14 changed files with 33 additions and 18 deletions

View File

Before

Width:  |  Height:  |  Size: 6.5 KiB

After

Width:  |  Height:  |  Size: 6.5 KiB

View File

Before

Width:  |  Height:  |  Size: 20 KiB

After

Width:  |  Height:  |  Size: 20 KiB

View File

Before

Width:  |  Height:  |  Size: 6.0 KiB

After

Width:  |  Height:  |  Size: 6.0 KiB

View File

@ -2,7 +2,7 @@
<browserconfig> <browserconfig>
<msapplication> <msapplication>
<tile> <tile>
<square150x150logo src="/mstile-150x150.png"/> <square150x150logo src="/favicon/mstile-150x150.png"/>
<TileColor>#00aba9</TileColor> <TileColor>#00aba9</TileColor>
</tile> </tile>
</msapplication> </msapplication>

View File

Before

Width:  |  Height:  |  Size: 843 B

After

Width:  |  Height:  |  Size: 843 B

View File

Before

Width:  |  Height:  |  Size: 1.2 KiB

After

Width:  |  Height:  |  Size: 1.2 KiB

View File

Before

Width:  |  Height:  |  Size: 15 KiB

After

Width:  |  Height:  |  Size: 15 KiB

View File

Before

Width:  |  Height:  |  Size: 3.5 KiB

After

Width:  |  Height:  |  Size: 3.5 KiB

View File

Before

Width:  |  Height:  |  Size: 5.0 KiB

After

Width:  |  Height:  |  Size: 5.0 KiB

View File

@ -3,15 +3,16 @@
<head> <head>
<meta charset="utf-8" /> <meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" /> <meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="theme-color" content="#000000" /> <meta name="description" content="Codenames, in the browser." />
<meta name="description" content="Codenames, on the web." />
<link rel="apple-touch-icon" sizes="180x180" href="%PUBLIC_URL%/apple-touch-icon.png" /> <link rel="apple-touch-icon" sizes="180x180" href="%PUBLIC_URL%/favicon/apple-touch-icon.png" />
<link rel="icon" type="image/png" sizes="32x32" href="%PUBLIC_URL%/favicon-32x32.png" /> <link rel="icon" type="image/png" sizes="32x32" href="%PUBLIC_URL%/favicon/favicon-32x32.png" />
<link rel="icon" type="image/png" sizes="16x16" href="%PUBLIC_URL%/favicon-16x16.png" /> <link rel="icon" type="image/png" sizes="16x16" href="%PUBLIC_URL%/favicon/favicon-16x16.png" />
<link rel="manifest" href="%PUBLIC_URL%/site.webmanifest" /> <link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
<link rel="mask-icon" href="%PUBLIC_URL%/safari-pinned-tab.svg" color="#5bbad5" /> <link rel="mask-icon" href="%PUBLIC_URL%/favicon/safari-pinned-tab.svg" color="#5bbad5" />
<link rel="shortcut icon" href="%PUBLIC_URL%/favicon/favicon.ico" />
<meta name="msapplication-TileColor" content="#00aba9" /> <meta name="msapplication-TileColor" content="#00aba9" />
<meta name="msapplication-config" content="%PUBLIC_URL%/favicon/browserconfig.xml" />
<meta name="theme-color" content="#ffffff" /> <meta name="theme-color" content="#ffffff" />
<title>Codies</title> <title>Codies</title>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.4 KiB

View File

@ -1,18 +1,19 @@
{ {
"name": "", "short_name": "Codies",
"short_name": "", "name": "Codies",
"icons": [ "icons": [
{ {
"src": "/android-chrome-192x192.png", "src": "/favicon/android-chrome-192x192.png",
"sizes": "192x192", "sizes": "192x192",
"type": "image/png" "type": "image/png"
}, },
{ {
"src": "/android-chrome-512x512.png", "src": "/favicon/android-chrome-512x512.png",
"sizes": "512x512", "sizes": "512x512",
"type": "image/png" "type": "image/png"
} }
], ],
"start_url": ".",
"theme_color": "#ffffff", "theme_color": "#ffffff",
"background_color": "#ffffff", "background_color": "#ffffff",
"display": "standalone" "display": "standalone"

25
main.go
View File

@ -58,12 +58,7 @@ func main() {
r := chi.NewMux() r := chi.NewMux()
r.Use(middleware.Heartbeat("/ping")) r.Use(middleware.Heartbeat("/ping"))
r.Use(middleware.Recoverer) r.Use(middleware.Recoverer)
r.NotFound(staticRouter().ServeHTTP)
r.Group(func(r chi.Router) {
r.Use(middleware.Compress(5))
fs := http.Dir("./frontend/build")
r.NotFound(http.FileServer(fs).ServeHTTP)
})
r.Group(func(r chi.Router) { r.Group(func(r chi.Router) {
r.Use(middleware.NoCache) r.Use(middleware.NoCache)
@ -204,6 +199,24 @@ func main() {
log.Fatal(g.Wait()) log.Fatal(g.Wait())
} }
func staticRouter() http.Handler {
fs := http.Dir("./frontend/build")
fsh := http.FileServer(fs)
r := chi.NewMux()
r.Use(middleware.Compress(5))
r.Handle("/static/*", fsh)
r.Handle("/favicon/*", fsh)
r.Group(func(r chi.Router) {
r.Use(middleware.NoCache)
r.Handle("/*", fsh)
})
return r
}
func httpErr(w http.ResponseWriter, code int) { func httpErr(w http.ResponseWriter, code int) {
http.Error(w, http.StatusText(code), code) http.Error(w, http.StatusText(code), code)
} }