mirror of https://github.com/shunfei/cronsun
embedded static assets
parent
809a025a7b
commit
880d7f94de
|
@ -5,5 +5,6 @@ dist
|
|||
bin/*/*server
|
||||
.DS_Store
|
||||
web/ui/node_modules
|
||||
web/ui/dist
|
||||
.vscode
|
||||
*npm-debug.log
|
||||
|
|
2
build.sh
2
build.sh
|
@ -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
|
||||
|
|
|
@ -73,7 +73,6 @@ type Conf struct {
|
|||
|
||||
type webConfig struct {
|
||||
BindAddr string
|
||||
UIDir string
|
||||
Auth struct {
|
||||
Enabled bool
|
||||
}
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
{
|
||||
"BindAddr": ":7079",
|
||||
"#UIDir": "为空使用默认的后台界面",
|
||||
"UIDir": "ui",
|
||||
"Auth": {
|
||||
"Enabled": false
|
||||
},
|
||||
|
|
|
@ -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/
|
|
@ -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"))
|
||||
}
|
||||
|
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
Binary file not shown.
Before Width: | Height: | Size: 28 KiB |
Binary file not shown.
File diff suppressed because it is too large
Load Diff
Before Width: | Height: | Size: 434 KiB |
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -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>
|
Loading…
Reference in New Issue