Skip to content

Commit

Permalink
feat: add icons and web manifest
Browse files Browse the repository at this point in the history
  • Loading branch information
ItsNotGoodName committed Jul 28, 2022
1 parent e92c5f4 commit be13796
Show file tree
Hide file tree
Showing 30 changed files with 141 additions and 19 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ jobs:
- uses: actions/setup-node@v2
with:
node-version: "16"
- run: npm install --prefix left/http/asset
- run: npm run build --prefix left/http/asset
- run: npm install --prefix left/http/static
- run: npm run build --prefix left/http/static
- name: Set up Go
uses: actions/setup-go@v2
with:
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
NPM_PREFIX := podman run --rm -it -v "$(shell pwd)/left/http/asset:/work" -w /work docker.io/library/node:16
NPM_PREFIX := podman run --rm -it -v "$(shell pwd)/left/http/static:/work" -w /work docker.io/library/node:16

all: npm snapshot

Expand Down
13 changes: 7 additions & 6 deletions left/http/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,15 @@ package http

import (
"context"
"io/fs"
"log"
"mime"
"net/http"
"time"

"github.com/ItsNotGoodName/smtpbridge/core/endpoint"
"github.com/ItsNotGoodName/smtpbridge/core/envelope"
"github.com/ItsNotGoodName/smtpbridge/left/http/asset"
c "github.com/ItsNotGoodName/smtpbridge/left/http/controller"
"github.com/ItsNotGoodName/smtpbridge/left/http/static"
"github.com/go-chi/chi/v5"
"github.com/go-chi/chi/v5/middleware"
)
Expand All @@ -25,7 +24,7 @@ type Server struct {
r chi.Router
}

func New(addr string, dataFS fs.FS, envelopeService envelope.Service, endpointService endpoint.Service) *Server {
func New(addr string, localDataStore envelope.LocalDataStore, envelopeService envelope.Service, endpointService endpoint.Service) *Server {
r := chi.NewRouter()

// A good base middleware stack
Expand All @@ -38,9 +37,11 @@ func New(addr string, dataFS fs.FS, envelopeService envelope.Service, endpointSe
// processing should be stopped.
r.Use(middleware.Timeout(60 * time.Second))

r.Get("/assets/*", handlePrefixFS("/assets/", asset.FS()))
mountFS(r, static.FS())

r.Get("/data/*", handlePrefixFS("/data/", dataFS))
r.Get("/assets/*", handlePrefixFS("/assets/", static.AssetFS()))

r.Get("/data/*", handlePrefixFS("/data/", localDataStore.DataFS()))

r.Get("/", c.IndexGet(envelopeService))

Expand Down Expand Up @@ -86,6 +87,6 @@ func (s *Server) Run(ctx context.Context, doneC chan<- struct{}) {
srv, ch := s.Start() // Start HTTP server
<-ctx.Done() // Wait for context
srv.Shutdown(context.Background()) // Shutdown HTTP server
<-ch // Wait for HTTP server shutodwn
<-ch // Wait for HTTP server shutdown
doneC <- struct{}{} // Done
}

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

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "asset",
"name": "static",
"version": "1.0.0",
"description": "",
"main": "index.js",
Expand Down
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 left/http/static/public/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 left/http/static/public/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="/mstile-150x150.png"/>
<TileColor>#2d89ef</TileColor>
</tile>
</msapplication>
</browserconfig>
Binary file added left/http/static/public/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 left/http/static/public/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 left/http/static/public/favicon.ico
Binary file not shown.
9 changes: 9 additions & 0 deletions left/http/static/public/favicon.svg
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 left/http/static/public/maskable_icon_x192.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 left/http/static/public/maskable_icon_x512.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 left/http/static/public/mstile-144x144.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 left/http/static/public/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.
Binary file added left/http/static/public/mstile-310x150.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 left/http/static/public/mstile-310x310.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 left/http/static/public/mstile-70x70.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 16 additions & 0 deletions left/http/static/public/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.
42 changes: 42 additions & 0 deletions left/http/static/public/site.webmanifest
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{
"$schema": "https://json.schemastore.org/web-manifest-combined.json",
"name": "SMTPBridge",
"short_name": "SMTPBridge",
"start_url": "/",
"display": "standalone",
"background_color": "#ffffff",
"lang": "en",
"scope": "/",
"description": "Bridge email to other messaging services.",
"theme_color": "#ffffff",
"icons": [
{
"src": "/android-chrome-192x192.png",
"sizes": "192x192",
"type": "image/png"
},
{
"src": "/android-chrome-512x512.png",
"sizes": "512x512",
"type": "image/png"
},
{
"src": "/maskable_icon_x192.png",
"sizes": "192x192",
"type": "image/png",
"purpose": "maskable"
},
{
"src": "/maskable_icon_x512.png",
"sizes": "512x512",
"type": "image/png",
"purpose": "maskable"
},
{
"src": "/favicon.svg",
"sizes": "any",
"type": "image/svg+xml",
"purpose": "any"
}
]
}
File renamed without changes.
File renamed without changes.
15 changes: 12 additions & 3 deletions left/http/asset/asset.go → left/http/static/static.go
Original file line number Diff line number Diff line change
@@ -1,20 +1,29 @@
//go:build !dev

package asset
package static

import (
"embed"
"io/fs"
)

//go:embed dist
//go:embed dist public
var assetFS embed.FS

func FS() fs.FS {
func AssetFS() fs.FS {
f, err := fs.Sub(assetFS, "dist")
if err != nil {
panic(err)
}

return f
}

func FS() fs.FS {
f, err := fs.Sub(assetFS, "public")
if err != nil {
panic(err)
}

return f
}
10 changes: 8 additions & 2 deletions left/http/asset/asset_dev.go → left/http/static/static_dev.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//go:build dev

package asset
package static

import (
"io/fs"
Expand All @@ -10,6 +10,7 @@ import (
)

var distFS fs.FS
var publicFS fs.FS

func init() {
_, filename, _, ok := runtime.Caller(0)
Expand All @@ -18,8 +19,13 @@ func init() {
}

distFS = os.DirFS(path.Join(path.Dir(filename), "dist"))
publicFS = os.DirFS(path.Join(path.Dir(filename), "public"))
}

func FS() fs.FS {
func AssetFS() fs.FS {
return distFS
}

func FS() fs.FS {
return publicFS
}
File renamed without changes.
21 changes: 21 additions & 0 deletions left/http/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ package http
import (
"fmt"
"io/fs"
"log"
"net/http"

"github.com/go-chi/chi/v5"
)

func mwMultiplexAction(get, post, delete http.HandlerFunc) http.HandlerFunc {
Expand Down Expand Up @@ -47,3 +50,21 @@ func handlePrefixFS(prefix string, fs fs.FS) http.HandlerFunc {
h.ServeHTTP(rw, r)
}
}

func mountFS(r chi.Router, f fs.FS) {
httpFS := http.FS(f)
fsHandler := http.StripPrefix("/", http.FileServer(httpFS))

if files, err := fs.ReadDir(f, "."); err == nil {
for _, f := range files {
name := f.Name()
if f.IsDir() {
r.Get("/"+name+"/*", fsHandler.ServeHTTP)
} else {
r.Get("/"+name, fsHandler.ServeHTTP)
}
}
} else if err != fs.ErrNotExist {
log.Fatalln("http.mountFS:", err)
}
}
11 changes: 10 additions & 1 deletion left/http/view/template/layout/default.html
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
{{ define "layout/default" }}
<!DOCTYPE html>
<html>
<html lang="en">

<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>SMTPBridge</title>
<meta name="description" content="Bridge email to other messaging services.">
<link rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon.png">
<link rel="icon" type="image/svg+xml" href="/favicon.svg">
<link rel="icon" type="image/png" sizes="32x32" href="/favicon-32x32.png">
<link rel="icon" type="image/png" sizes="16x16" href="/favicon-16x16.png">
<link rel="manifest" href="/site.webmanifest">
<link rel="mask-icon" href="/safari-pinned-tab.svg" color="#5bbad5">
<meta name="msapplication-TileColor" content="#da532c">
<meta name="theme-color" content="#ffffff">
<link rel="stylesheet" href="/assets/css/index.css">
<script src="/assets/js/bundle.js"></script>
</head>
Expand Down
2 changes: 1 addition & 1 deletion server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ func Start(ctx context.Context, config *config.Config) <-chan struct{} {
if !config.HTTP.Disable {
backgrounds = append(backgrounds, http.New(
config.HTTP.Addr(),
dataStore.(envelope.LocalDataStore).DataFS(),
dataStore.(envelope.LocalDataStore),
envelopeService,
endpointService,
))
Expand Down

0 comments on commit be13796

Please sign in to comment.