Skip to content

Commit

Permalink
Move all web code to its own folder
Browse files Browse the repository at this point in the history
  • Loading branch information
rsierra committed Apr 16, 2020
1 parent 4c4f505 commit cf93c56
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 16 deletions.
11 changes: 5 additions & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ RUN go mod download
# Copy the source from the current directory to the Working Directory inside the container
COPY . .

# There is a roblem with net lib bindings and CGO_ENABLED is needed
# There is a problem with net lib bindings and CGO_ENABLED is needed
# https://stackoverflow.com/questions/36279253/go-compiled-binary-wont-run-in-an-alpine-docker-container-on-ubuntu-host
RUN CGO_ENABLED=0 go build -o server -v .
RUN CGO_ENABLED=0 go build -o file-qrs -v .

# ==============================
# Stage 2: Run the isolated build in a lightweight image
Expand All @@ -28,11 +28,10 @@ EXPOSE 8100
ARG HTPASSWD_FILE
ENV HTPASSWD_FILE ${HTPASSWD_FILE:-""}

ENTRYPOINT ["/app/server"]
ENTRYPOINT ["/app/file-qrs"]
CMD ["-p", "8100", "-d", "/files"]

COPY statics/ ./statics
COPY templates/ ./templates
COPY --from=builder /go/src/app/server ./
COPY web/ ./web
COPY --from=builder /go/src/app/file-qrs ./

VOLUME /files
13 changes: 7 additions & 6 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@ package main
import (
"flag"
"fmt"
auth "github.com/abbot/go-http-auth"
"html/template"
"io/ioutil"
"log"
"net/http"
"os"
"path/filepath"

auth "github.com/abbot/go-http-auth"
)

var port = flag.String("p", "8100", "port to serve on")
Expand All @@ -27,10 +28,10 @@ func main() {
flag.Parse()

fs := http.FileServer(http.Dir(*root_folder))
http.Handle("/_app/files/", http.StripPrefix("/_app/files/", fs))
http.Handle("/web/files/", http.StripPrefix("/web/files/", fs))

ss := http.FileServer(http.Dir("statics"))
http.Handle("/_app/statics/", http.StripPrefix("/_app/statics/", ss))
ss := http.FileServer(http.Dir("web/assets"))
http.Handle("/web/assets/", http.StripPrefix("/web/assets/", ss))

htppasswd := os.Getenv("HTPASSWD_FILE")
if htppasswd == "" {
Expand Down Expand Up @@ -66,8 +67,8 @@ func serveTemplate(w http.ResponseWriter, r *http.Request) {
Folders []string
}{FolderToWeb(request_path), FolderToWeb(filepath.Dir(request_path)), files, folders}

lp := filepath.Join("templates", "layout.html")
fp := filepath.Join("templates", "index.html")
lp := filepath.Join("web", "templates", "layout.html")
fp := filepath.Join("web", "templates", "index.html")
tmpl, _ := template.ParseFiles(lp, fp)
tmpl.ExecuteTemplate(w, "layout", data)
}
Expand Down
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions templates/index.html → web/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ <h1>Files list in <b>'{{$data.CurrentFolder}}'</b></h1>
{{end}}
{{range $file := $data.Files}}
<li>
<a href="/_app/files{{$data.CurrentFolder}}{{$file}}" class="qr-link"><i class="fa fa-qrcode"></i></a>
<a href="/web/files{{$data.CurrentFolder}}{{$file}}" class="qr-link"><i class="fa fa-qrcode"></i></a>
<a href="/web/files{{$data.CurrentFolder}}{{$file}}" download><i class="fa fa-download"></i></a>
{{.}}
<!-- <a href="/_app/files{{$data.CurrentFolder}}{{$file}}" download><i class="fa fa-download"></i></a> -->
</li>
{{end}}
</ul>
Expand Down
4 changes: 2 additions & 2 deletions templates/layout.html → web/templates/layout.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<head>
<link href="https://cdn.jsdelivr.net/npm/font-awesome@4.7.0/css/font-awesome.min.css" rel="stylesheet">
<link rel="stylesheet" type="text/css" href="/_app/statics/css/app.css">
<link rel="stylesheet" type="text/css" href="/web/assets/css/app.css">
<link
href="data:image/x-icon;base64,AAABAAEAEBACAAAAAACwAAAAFgAAACgAAAAQAAAAIAAAAAEAAQAAAAAAQAAAAAAAAAAAAAAAAgAAAAAAAAAAAAAA////AAKnAAB6MgAASlIAAEtCAAB7AAAAAnkAAP/YAACDBQAAUGMAAPy/AAACQAAAel4AAEpSAABK0gAAel4AAAJAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
rel="icon" type="image/x-icon" />
Expand All @@ -16,7 +16,7 @@

<body>
{{template "body" .}}
<script type='text/javascript' src="/_app/statics/js/app.js"></script>
<script type='text/javascript' src="/web/assets/js/app.js"></script>
</body>

</html>
Expand Down

0 comments on commit cf93c56

Please sign in to comment.