Skip to content

Commit

Permalink
Merge pull request #626 from ansible-semaphore/fix-static-content-rou…
Browse files Browse the repository at this point in the history
…ting

Fix static content routing
  • Loading branch information
fiftin committed Nov 23, 2020
2 parents 620e873 + 060f4d9 commit a36d23e
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 37 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Expand Up @@ -9,7 +9,7 @@ aliases:
# git clone -b $CIRCLE_BRANCH https://github.com/ansible-semaphore/semaphore.git ./

- &golang-image
image: circleci/golang:1.15.5
image: circleci/golang:1.13

- &working-dir
/go/src/github.com/ansible-semaphore/semaphore
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Expand Up @@ -4,8 +4,8 @@ web/public/js/bundle.js
web/public/css/*.*
web/public/html/**/*.*
web/public/fonts/*.*
web2/dist
web2/.nyc_output
web2/dist/**/*
config.json
.DS_Store
node_modules/
Expand Down
1 change: 1 addition & 0 deletions Taskfile.yml
Expand Up @@ -127,6 +127,7 @@ tasks:
- db/db-packr.go
- api/api-packr.go
cmds:
- mkdir -p web2/dist
- go run util/version_gen/generator.go {{ if .TAG }}{{ .TAG }}{{ else }}{{ if .SEMAPHORE_VERSION }}{{ .SEMAPHORE_VERSION }}{{ else }}{{ .BRANCH }}-{{ .SHA }}-{{ .TIMESTAMP }}{{ if .DIRTY }}-dirty{{ end }}{{ end }}{{end}}
- packr
vars:
Expand Down
26 changes: 14 additions & 12 deletions api/router.go
Expand Up @@ -16,15 +16,8 @@ import (
"github.com/russross/blackfriday"
)

var publicAssets packr.Box

func getPublicAssetsPath() string {
if util.Config != nil && util.Config.OldFrontend {
return "../web/public"
}

return "../web2/dist"
}
var publicAssets = packr.NewBox("../web/public")
var publicAssets2 = packr.NewBox("../web2/dist")

//JSONMiddleware ensures that all the routes respond with Json, this is added by default to all routes
func JSONMiddleware(next http.Handler) http.Handler {
Expand Down Expand Up @@ -58,8 +51,6 @@ func notFoundHandler(w http.ResponseWriter, r *http.Request) {

// Route declares all routes
func Route() *mux.Router {
publicAssets = packr.NewBox(getPublicAssetsPath())

r := mux.NewRouter().StrictSlash(true)
r.NotFoundHandler = http.HandlerFunc(servePublic)

Expand Down Expand Up @@ -271,7 +262,18 @@ func servePublic(w http.ResponseWriter, r *http.Request) {
split := strings.Split(path, ".")
suffix := split[len(split)-1]

res, err := publicAssets.MustBytes(path)
fmt.Println("path")
fmt.Println(path)

var res []byte
var err error

if util.Config.OldFrontend {
res, err = publicAssets.MustBytes(path)
} else {
res, err = publicAssets2.MustBytes(path)
}

if err != nil {
notFoundHandler(w, r)
return
Expand Down
23 changes: 0 additions & 23 deletions web2/.gitignore

This file was deleted.

0 comments on commit a36d23e

Please sign in to comment.