dashboard: handle correctly baseurl option
On the first public.html GET, load the index.html file, as Go Template.
This commit is contained in:
parent
ca891cd9b2
commit
ded583008a
|
@ -66,7 +66,7 @@ func StripPrefix(prefix string, h http.Handler) http.Handler {
|
|||
func main() {
|
||||
// Read parameters from command line
|
||||
var bind = flag.String("bind", "127.0.0.1:8082", "Bind port/socket")
|
||||
var baseURL = flag.String("baseurl", "/", "URL prepended to each URL")
|
||||
flag.StringVar(&BaseURL, "baseurl", BaseURL, "URL prepended to each URL")
|
||||
flag.StringVar(&StaticDir, "static", "./htdocs-dashboard/", "Directory containing static files")
|
||||
flag.StringVar(&fic.FilesDir, "files", fic.FilesDir, "Base directory where found challenges files, local part")
|
||||
flag.StringVar(&DashboardDir, "dashbord", "./DASHBOARD", "Base directory where save public JSON files")
|
||||
|
@ -90,12 +90,10 @@ func main() {
|
|||
if settings.SettingsDir, err = filepath.Abs(settings.SettingsDir); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
if *baseURL != "/" {
|
||||
tmp := path.Clean(*baseURL)
|
||||
baseURL = &tmp
|
||||
if BaseURL != "/" {
|
||||
BaseURL = path.Clean(BaseURL)
|
||||
} else {
|
||||
tmp := ""
|
||||
baseURL = &tmp
|
||||
BaseURL = ""
|
||||
}
|
||||
if fwdr != nil && len(*fwdr) > 0 {
|
||||
forwarder = fwdr
|
||||
|
@ -107,7 +105,7 @@ func main() {
|
|||
|
||||
srv := &http.Server{
|
||||
Addr: *bind,
|
||||
Handler: StripPrefix(*baseURL, api.Router()),
|
||||
Handler: StripPrefix(BaseURL, api.Router()),
|
||||
}
|
||||
|
||||
// Serve content
|
||||
|
|
|
@ -1,8 +1,13 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
"path"
|
||||
"strings"
|
||||
"time"
|
||||
|
@ -14,16 +19,37 @@ import (
|
|||
"github.com/julienschmidt/httprouter"
|
||||
)
|
||||
|
||||
var BaseURL = "/"
|
||||
var forwarder *string = nil
|
||||
var fwdPublicJson = false
|
||||
|
||||
var indexTmpl []byte
|
||||
|
||||
func getIndexHtml(w io.Writer) {
|
||||
if len(indexTmpl) == 0 {
|
||||
if file, err := os.Open(path.Join(StaticDir, "index.html")); err != nil {
|
||||
log.Println("Unable to open index.html: ", err)
|
||||
} else {
|
||||
defer file.Close()
|
||||
|
||||
if indexTmpl, err = ioutil.ReadAll(file); err != nil {
|
||||
log.Println("Cannot read whole index.html: ", err)
|
||||
} else {
|
||||
indexTmpl = bytes.Replace(indexTmpl, []byte("{{.urlbase}}"), []byte(path.Clean(path.Join(BaseURL+"/", "nuke"))[:len(path.Clean(path.Join(BaseURL+"/", "nuke")))-4]), -1)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
w.Write(indexTmpl)
|
||||
}
|
||||
|
||||
func init() {
|
||||
api.Router().GET("/", func(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
||||
http.ServeFile(w, r, path.Join(StaticDir, "index.html"))
|
||||
http.Redirect(w, r, "public0.html", http.StatusFound)
|
||||
})
|
||||
for i := 0; i <= 9; i++ {
|
||||
api.Router().GET(fmt.Sprintf("/public%d.html", i), func(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
||||
http.ServeFile(w, r, path.Join(StaticDir, "index.html"))
|
||||
getIndexHtml(w)
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
@ -8,11 +8,11 @@
|
|||
<link rel="shortcut icon" type="image/x-icon" href="/favicon.ico">
|
||||
<meta name="author" content="EPITA Laboratoire SRS">
|
||||
<meta name="robots" content="all">
|
||||
<base href="/">
|
||||
<link href="/css/bootstrap.min.css" type="text/css" rel="stylesheet" media="screen">
|
||||
<link href="/css/glyphicon.css" type="text/css" rel="stylesheet" media="screen">
|
||||
<link href="/css/fic.css" type="text/css" rel="stylesheet" media="screen">
|
||||
<script src="/js/angular.min.js"></script>
|
||||
<base href="{{.urlbase}}">
|
||||
<link href="{{.urlbase}}/css/bootstrap.min.css" type="text/css" rel="stylesheet" media="screen">
|
||||
<link href="{{.urlbase}}/css/glyphicon.css" type="text/css" rel="stylesheet" media="screen">
|
||||
<link href="{{.urlbase}}/css/fic.css" type="text/css" rel="stylesheet" media="screen">
|
||||
<script src="{{.urlbase}}/js/angular.min.js"></script>
|
||||
</head>
|
||||
<body class="bg-light bg-public" style="overflow: hidden;" class="container-fluid" ng-controller="DataController">
|
||||
<div class="row" style="margin:10px 0">
|
||||
|
@ -554,13 +554,13 @@
|
|||
|
||||
</div>
|
||||
|
||||
<script src="/js/jquery.min.js"></script>
|
||||
<script src="/js/bootstrap.min.js"></script>
|
||||
<script src="/js/angular-animate.min.js"></script>
|
||||
<script src="/js/angular-route.min.js"></script>
|
||||
<script src="/js/angular-sanitize.min.js"></script>
|
||||
<script src="/js/i18n/angular-locale_fr-fr.js"></script>
|
||||
<script src="/js/dashboard.js"></script>
|
||||
<script src="/js/common.js"></script>
|
||||
<script src="{{.urlbase}}/js/jquery.min.js"></script>
|
||||
<script src="{{.urlbase}}/js/bootstrap.min.js"></script>
|
||||
<script src="{{.urlbase}}/js/angular-animate.min.js"></script>
|
||||
<script src="{{.urlbase}}/js/angular-route.min.js"></script>
|
||||
<script src="{{.urlbase}}/js/angular-sanitize.min.js"></script>
|
||||
<script src="{{.urlbase}}/js/i18n/angular-locale_fr-fr.js"></script>
|
||||
<script src="{{.urlbase}}/js/dashboard.js"></script>
|
||||
<script src="{{.urlbase}}/js/common.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
|
Loading…
Reference in New Issue