embedded static assets

pull/45/head
Doflatango 2017-08-30 14:56:50 +08:00
parent 809a025a7b
commit 880d7f94de
16 changed files with 467 additions and 2801 deletions

1
.gitignore vendored
View File

@ -5,5 +5,6 @@ dist
bin/*/*server
.DS_Store
web/ui/node_modules
web/ui/dist
.vscode
*npm-debug.log

View File

@ -18,8 +18,6 @@ check_code
go build -o ./$out/cronweb ./bin/web/server.go
check_code
cp -r web/ui/dist "$out/ui"
sources=`find ./conf/files -name "*.json.sample"`
check_code
for source in $sources;do

View File

@ -73,7 +73,6 @@ type Conf struct {
type webConfig struct {
BindAddr string
UIDir string
Auth struct {
Enabled bool
}

View File

@ -1,7 +1,5 @@
{
"BindAddr": ":7079",
"#UIDir": "为空使用默认的后台界面",
"UIDir": "ui",
"Auth": {
"Enabled": false
},

6
web/gen_bindata.sh Normal file
View File

@ -0,0 +1,6 @@
#!/bin/sh
cd ui
npm run build
cd ..
go-bindata -pkg "web" -prefix "ui/dist/" -o static_assets.go ./ui/dist/

View File

@ -3,11 +3,11 @@ package web
import (
"net/http"
"path"
"strings"
"github.com/gorilla/mux"
"github.com/shunfei/cronsun"
"github.com/shunfei/cronsun/conf"
)
func GetVersion(ctx *Context) {
@ -101,14 +101,49 @@ func initRouters() (s *http.Server, err error) {
h = NewAuthHandler(configHandler.Configuratios)
subrouter.Handle("/configurations", h).Methods("GET")
uidir := conf.Config.Web.UIDir
if len(uidir) == 0 {
uidir = path.Join("web", "ui", "dist")
}
r.PathPrefix("/ui/").Handler(http.StripPrefix("/ui/", http.FileServer(http.Dir(uidir))))
r.PathPrefix("/ui/").Handler(http.StripPrefix("/ui/", newEmbeddedFileServer("", "index.html")))
s = &http.Server{
Handler: r,
}
return s, nil
}
type embeddedFileServer struct {
Prefix string
IndexFile string
}
func newEmbeddedFileServer(prefix, index string) *embeddedFileServer {
index = strings.TrimLeft(index, "/")
return &embeddedFileServer{Prefix: prefix, IndexFile: index}
}
func (s *embeddedFileServer) ServeHTTP(w http.ResponseWriter, r *http.Request) {
fp := path.Clean(s.Prefix + r.URL.Path)
if fp == "." {
fp = ""
} else {
fp = strings.TrimLeft(fp, "/")
}
b, err := Asset(fp)
if err == nil {
w.Write(b)
return
}
if len(fp) > 0 {
fp += "/"
}
fp += s.IndexFile
b, err = Asset(fp)
if err == nil {
w.Write(b)
return
}
w.WriteHeader(http.StatusNotFound)
w.Write([]byte("404 page not found"))
}

419
web/static_assets.go Normal file

File diff suppressed because one or more lines are too long

51
web/ui/dist/build.js vendored

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

BIN
web/ui/dist/flags.png vendored

Binary file not shown.

Before

Width:  |  Height:  |  Size: 28 KiB

BIN
web/ui/dist/icons.eot vendored

Binary file not shown.

2671
web/ui/dist/icons.svg vendored

File diff suppressed because it is too large Load Diff

Before

Width:  |  Height:  |  Size: 434 KiB

BIN
web/ui/dist/icons.ttf vendored

Binary file not shown.

BIN
web/ui/dist/icons.woff vendored

Binary file not shown.

Binary file not shown.

View File

@ -1,67 +0,0 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Cronsun Managerment</title>
<style>
.initial.error {
margin: 170px 80px;
color: red;
font-size: 2em;
line-height: 2em;
}
#initloader,
#initloader:after {
border-radius: 50%;
width: 10em;
height: 10em;
}
#initloader {
margin: 180px auto;
font-size: 10px;
position: relative;
text-indent: -9999em;
border: 1.1em solid rgba(9, 47, 181, 0.2);
border-left: 1.1em solid #2185d0;
-webkit-transform: translateZ(0);
-ms-transform: translateZ(0);
transform: translateZ(0);
-webkit-animation: load8 1.1s infinite linear;
animation: load8 1.1s infinite linear;
}
@-webkit-keyframes load8 {
0% {
-webkit-transform: rotate(0deg);
transform: rotate(0deg);
}
100% {
-webkit-transform: rotate(360deg);
transform: rotate(360deg);
}
}
@keyframes load8 {
0% {
-webkit-transform: rotate(0deg);
transform: rotate(0deg);
}
100% {
-webkit-transform: rotate(360deg);
transform: rotate(360deg);
}
}
</style>
</head>
<body>
<div id="app">
<div id="initloader"></div>
</div>
<script src="build.js"></script>
</body>
</html>