Skip to content

Commit

Permalink
fix: fix static assets url generation (#965)
Browse files Browse the repository at this point in the history
  • Loading branch information
o1egl committed May 31, 2020
1 parent 6e5405e commit ba47e3b
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 13 deletions.
14 changes: 7 additions & 7 deletions frontend/public/index.html
Expand Up @@ -11,8 +11,8 @@

<title>[{[ if .Name -]}][{[ .Name ]}][{[ else ]}]File Browser[{[ end ]}]</title>

<link rel="icon" type="image/png" sizes="32x32" href="/[{[ .StaticURL ]}]/img/icons/favicon-32x32.png">
<link rel="icon" type="image/png" sizes="16x16" href="/[{[ .StaticURL ]}]/img/icons/favicon-16x16.png">
<link rel="icon" type="image/png" sizes="32x32" href="[{[ .StaticURL ]}]/img/icons/favicon-32x32.png">
<link rel="icon" type="image/png" sizes="16x16" href="[{[ .StaticURL ]}]/img/icons/favicon-16x16.png">
<!-- Add to home screen for Android and modern mobile browsers -->
<link rel="manifest" id="manifestPlaceholder" crossorigin="use-credentials">
<meta name="theme-color" content="#2979ff">
Expand All @@ -21,17 +21,17 @@
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<meta name="apple-mobile-web-app-title" content="assets">
<link rel="apple-touch-icon" href="/[{[ .StaticURL ]}]/img/icons/apple-touch-icon-152x152.png">
<link rel="apple-touch-icon" href="[{[ .StaticURL ]}]/img/icons/apple-touch-icon-152x152.png">

<!-- Add to home screen for Windows -->
<meta name="msapplication-TileImage" content="/[{[ .StaticURL ]}]/img/icons/msapplication-icon-144x144.png">
<meta name="msapplication-TileImage" content="[{[ .StaticURL ]}]/img/icons/msapplication-icon-144x144.png">
<meta name="msapplication-TileColor" content="#2979ff">

<!-- Inject Some Variables and generate the manifest json -->
<script>
window.FileBrowser = JSON.parse(`[{[ .Json ]}]`);

var fullStaticURL = window.location.origin + "/" + window.FileBrowser.StaticURL;
var fullStaticURL = window.location.origin + window.FileBrowser.StaticURL;
var dynamicManifest = {
"name": window.FileBrowser.Name || 'File Browser',
"short_name": window.FileBrowser.Name || 'File Browser',
Expand Down Expand Up @@ -134,10 +134,10 @@
</div>

[{[ if .Theme -]}]
<link rel="stylesheet" href="/[{[ .StaticURL ]}]/themes/[{[ .Theme ]}].css" />
<link rel="stylesheet" href="[{[ .StaticURL ]}]/themes/[{[ .Theme ]}].css" />
[{[ end ]}]
[{[ if .CSS -]}]
<link rel="stylesheet" href="/[{[ .StaticURL ]}]/custom.css" />
<link rel="stylesheet" href="[{[ .StaticURL ]}]/custom.css" />
[{[ end ]}]
</body>
</html>
2 changes: 1 addition & 1 deletion frontend/src/utils/constants.js
Expand Up @@ -6,7 +6,7 @@ const recaptcha = window.FileBrowser.ReCaptcha
const recaptchaKey = window.FileBrowser.ReCaptchaKey
const signup = window.FileBrowser.Signup
const version = window.FileBrowser.Version
const logoURL = `/${staticURL}/img/logo.svg`
const logoURL = `${staticURL}/img/logo.svg`
const noAuth = window.FileBrowser.NoAuth
const authMethod = window.FileBrowser.AuthMethod
const loginPage = window.FileBrowser.LoginPage
Expand Down
3 changes: 2 additions & 1 deletion http/share.go
Expand Up @@ -4,6 +4,7 @@ import (
"crypto/rand"
"encoding/base64"
"net/http"
"path"
"strconv"
"strings"
"time"
Expand Down Expand Up @@ -56,7 +57,7 @@ var sharePostHandler = withPermShare(func(w http.ResponseWriter, r *http.Request
var err error
s, err = d.store.Share.GetPermanent(r.URL.Path, d.user.ID)
if err == nil {
w.Write([]byte(d.server.BaseURL + "/share/" + s.Hash))
w.Write([]byte(path.Join(d.server.BaseURL, "/share/", s.Hash)))
return 0, nil
}
}
Expand Down
5 changes: 2 additions & 3 deletions http/static.go
Expand Up @@ -5,6 +5,7 @@ import (
"log"
"net/http"
"os"
"path"
"path/filepath"
"strings"
"text/template"
Expand All @@ -19,8 +20,6 @@ import (
func handleWithStaticData(w http.ResponseWriter, r *http.Request, d *data, box *rice.Box, file, contentType string) (int, error) {
w.Header().Set("Content-Type", contentType)

staticURL := strings.TrimPrefix(d.server.BaseURL+"/static", "/")

auther, err := d.store.Auth.Get(d.settings.AuthMethod)
if err != nil {
return http.StatusInternalServerError, err
Expand All @@ -31,7 +30,7 @@ func handleWithStaticData(w http.ResponseWriter, r *http.Request, d *data, box *
"DisableExternal": d.settings.Branding.DisableExternal,
"BaseURL": d.server.BaseURL,
"Version": version.Version,
"StaticURL": staticURL,
"StaticURL": path.Join(d.server.BaseURL, "/static"),
"Signup": d.settings.Signup,
"NoAuth": d.settings.AuthMethod == auth.MethodNoAuth,
"AuthMethod": d.settings.AuthMethod,
Expand Down
2 changes: 1 addition & 1 deletion http/utils.go
Expand Up @@ -43,7 +43,7 @@ func errToStatus(err error) int {
// This is an addaptation if http.StripPrefix in which we don't
// return 404 if the page doesn't have the needed prefix.
func stripPrefix(prefix string, h http.Handler) http.Handler {
if prefix == "" {
if prefix == "" || prefix == "/" {
return h
}

Expand Down

0 comments on commit ba47e3b

Please sign in to comment.