Skip to content

Commit

Permalink
Merge pull request #6 from jsnjack/go116
Browse files Browse the repository at this point in the history
Use go:embed
  • Loading branch information
jsnjack authored Jan 20, 2021
2 parents bd9369b + 8fd2c78 commit 460df58
Show file tree
Hide file tree
Showing 11 changed files with 41 additions and 59 deletions.
7 changes: 4 additions & 3 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
"source.fixAll.eslint": true
},
"eslint.workingDirectories": ["src/frontend/"],
"go.languageServerExperimentalFeatures": {
"rename": true
},
"gopls": {
"buildFlags": ["-tags=wireinject"],
"experimentalWorkspaceModule": true
},
}
22 changes: 5 additions & 17 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,14 @@ export VUE_APP_VERSION = ${VERSION}-${VUE_VERSION_SUFFIX}
.ONESHELL:
src/backend/wakeci: version src/backend/*.go
cd src/backend
rm -f rice-box.go
go build -ldflags="-X main.Version=${VERSION}" -o ${BINARY}
rm -rf assets
cp -r ../frontend/dist/ assets
CGO_ENABLED=0 go build -ldflags="-X main.Version=${VERSION}" -o ${BINARY}

.ONESHELL:
bin/wakeci: version src/backend/*.go
bin/wakeci: src/backend/wakeci
cd src/backend
rm -f rice-box.go
rice embed-go || exit 1
CGO_ENABLED=0 go build -ldflags="-X main.Version=${VERSION}" -o ${BINARY}
mv wakeci ${PWD}/bin/
cp wakeci ${PWD}/bin/

runf:
cd src/frontend && npm run serve
Expand All @@ -41,16 +39,6 @@ buildf:

build: buildf bin/wakeci

deploy: build
ssh wakeci mkdir wakedir
ssh wakeci mkdir wakeconfig
ssh wakeci sudo systemctl stop ${BINARY} || exit 0
ssh wakeci rm -f ${BINARY}
scp bin/${BINARY} wakeci:~/
ssh wakeci sudo setcap cap_net_bind_service=+ep ${BINARY}
ssh wakeci sudo systemctl start ${BINARY}
ssh wakeci sudo systemctl status ${BINARY}

release: build
grm release jsnjack/wakeci -f bin/${BINARY} -t "v`monova`"

Expand Down
5 changes: 0 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,3 @@ jobdir: ./
### API documentation
See full description [here](https://github.com/jsnjack/wakeci/blob/master/API.md)

### For developers
#### Build dependencies
```bash
sudo dnf install golang-github-geertjohan-rice
```
3 changes: 1 addition & 2 deletions src/backend/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
wakeci
vendor/
rice-box.go
assets
5 changes: 2 additions & 3 deletions src/backend/go.mod
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
module wakeci

go 1.13
go 1.16

require (
github.com/GeertJohan/go.rice v1.0.2
github.com/NYTimes/gziphandler v1.1.1
github.com/bmatcuk/doublestar v1.3.4
github.com/daaku/go.zipexe v1.0.1 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/go-cmd/cmd v1.2.0 // indirect
github.com/gofrs/uuid v4.0.0+incompatible
github.com/gorilla/websocket v1.4.2
Expand Down
11 changes: 0 additions & 11 deletions src/backend/go.sum
Original file line number Diff line number Diff line change
@@ -1,14 +1,7 @@
github.com/GeertJohan/go.incremental v1.0.0/go.mod h1:6fAjUhbVuX1KcMD3c8TEgVUqmo4seqhv0i0kdATSkM0=
github.com/GeertJohan/go.rice v1.0.2 h1:PtRw+Tg3oa3HYwiDBZyvOJ8LdIyf6lAovJJtr7YOAYk=
github.com/GeertJohan/go.rice v1.0.2/go.mod h1:af5vUNlDNkCjOZeSGFgIJxDje9qdjsO6hshx0gTmZt4=
github.com/NYTimes/gziphandler v1.1.1 h1:ZUDjpQae29j0ryrS0u/B8HZfJBtBQHjqw2rQ2cqUQ3I=
github.com/NYTimes/gziphandler v1.1.1/go.mod h1:n/CVRwUEOgIxrgPvAQhUUr9oeUtvrhMomdKFjzJNB0c=
github.com/akavel/rsrc v0.8.0/go.mod h1:uLoCtb9J+EyAqh+26kdrTgmzRBFPGOolLWKpdxkKq+c=
github.com/bmatcuk/doublestar v1.3.4 h1:gPypJ5xD31uhX6Tf54sDPUOBXTqKH4c9aPY66CyQrS0=
github.com/bmatcuk/doublestar v1.3.4/go.mod h1:wiQtGV+rzVYxB7WIlirSN++5HPtPlXEo9MEoZQC/PmE=
github.com/daaku/go.zipexe v1.0.0/go.mod h1:z8IiR6TsVLEYKwXAoE/I+8ys/sDkgTzSL0CLnGVd57E=
github.com/daaku/go.zipexe v1.0.1 h1:wV4zMsDOI2SZ2m7Tdz1Ps96Zrx+TzaK15VbUaGozw0M=
github.com/daaku/go.zipexe v1.0.1/go.mod h1:5xWogtqlYnfBXkSB1o9xysukNP9GTvaNkqzUZbt3Bw8=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
Expand All @@ -20,12 +13,10 @@ github.com/gofrs/uuid v4.0.0+incompatible h1:1SD/1F5pU8p29ybwgQSwpQk+mwdRrXCYuPh
github.com/gofrs/uuid v4.0.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM=
github.com/gorilla/websocket v1.4.2 h1:+/TMaTYc4QFitKJxsQ7Yye35DkWvkdLcvGKqM+x0Ufc=
github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI=
github.com/jsnjack/cmd v1.0.6-0.20200228215332-45cf13c519c4 h1:ratfe5IRiMI6/kzQt3xTPVoUYXtiC/yEaRqRSvZdQOc=
github.com/jsnjack/cmd v1.0.6-0.20200228215332-45cf13c519c4/go.mod h1:f14kglzXmlAgGKitIHA4NC7BxUQ+eqa2l4LfUzRz5tg=
github.com/julienschmidt/httprouter v1.3.0 h1:U0609e9tgbseu3rBINet9P48AI/D3oJs4dN7jwJOQ1U=
github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8IZAc4RVcycCCAKdM=
github.com/nkovacs/streamquote v1.0.0/go.mod h1:BN+NaZ2CmdKqUuTUXUEm9j95B2TRbpOWpxbJYzzgUsc=
github.com/petermattis/goid v0.0.0-20180202154549-b0b1615b78e5 h1:q2e307iGHPdTGp0hoxKjt1H5pDo6utceo3dQVK3I5XQ=
github.com/petermattis/goid v0.0.0-20180202154549-b0b1615b78e5/go.mod h1:jvVRKCrJTQWu0XVbaOlby/2lO20uSCHEMzzplHXte1o=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
Expand All @@ -37,8 +28,6 @@ github.com/sasha-s/go-deadlock v0.2.0/go.mod h1:StQn567HiB1fF2yJ44N9au7wOhrPS3iZ
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
github.com/valyala/fasttemplate v1.0.1/go.mod h1:UQGH1tvbgY+Nz5t2n7tXsz52dQxojPUpymEIMZ47gx8=
go.etcd.io/bbolt v1.3.5 h1:XAzx9gjCb0Rxj7EoqcClPD1d5ZBxZJk0jbuoPHenBt0=
go.etcd.io/bbolt v1.3.5/go.mod h1:G5EMThwa9y8QZGBClrRx5EY+Yw9kAhnjy3bSjsnlVTQ=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
Expand Down
7 changes: 4 additions & 3 deletions src/backend/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"crypto/tls"
"embed"
"flag"
"log"
"net/http"
Expand All @@ -10,7 +11,6 @@ import (
"golang.org/x/crypto/acme/autocert"
"golang.org/x/crypto/bcrypt"

rice "github.com/GeertJohan/go.rice"
"github.com/NYTimes/gziphandler"
"github.com/julienschmidt/httprouter"
"github.com/robfig/cron/v3"
Expand Down Expand Up @@ -134,9 +134,10 @@ func main() {
HostPolicy: autocert.HostWhitelist(Config.Hostname),
}

vueBox := rice.MustFindBox("../frontend/dist/").HTTPBox()
//go:embed assets/*
var assets embed.FS

vuefs := http.FileServer(vueBox)
vuefs := http.FileServer(http.FS(assets))
storageServer := http.FileServer(http.Dir(Config.WorkDir + "wakespace"))
// Configure routes
router := httprouter.New()
Expand Down
30 changes: 17 additions & 13 deletions src/backend/middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,25 +151,29 @@ func VueResourcesMi(h http.Handler) http.Handler {
if !ok {
logger = Logger
}
// First check if it is any of API or AUTH calls
if strings.HasPrefix(r.URL.Path, "/api/") || strings.HasPrefix(r.URL.Path, "/auth/") {
w.WriteHeader(http.StatusNotFound)
logger.Printf("vue 404 %s\n", r.URL.Path)
// First check if it is any of API, AUTH or STORAGE calls. This urls
// should never reach this point
switch {
case strings.HasPrefix(r.URL.Path, "/api/"), strings.HasPrefix(r.URL.Path, "/auth/"), strings.HasPrefix(r.URL.Path, "/storage/"):
w.WriteHeader(http.StatusInternalServerError)
logger.Printf("vue 500 %s\n", r.URL.Path)
return
}
// Static file or root address
if strings.Contains(r.URL.Path, ".") || r.URL.Path == "/" {
logger.Printf("vue GET %s\n", r.URL.Path)
h.ServeHTTP(w, r)
return
}
// Most likely this is request to one of the dynamic URLs used by frontend,
// serve index.html (/) in this case

r2 := new(http.Request)
*r2 = *r
r2.URL = new(url.URL)
*r2.URL = *r.URL
r2.URL.Path = "/"
switch {
case strings.Contains(r.URL.Path, "."), r.URL.Path == "/":
// Static file or root address
r2.URL.Path = "/assets" + r.URL.Path
break
default:
// Most likely this is request to one of the dynamic URLs used by frontend,
// serve index.html (/assets/) in this case
r2.URL.Path = "/assets/"
}
logger.Printf("vue %s --> %s\n", r.URL.Path, r2.URL.Path)
h.ServeHTTP(w, r2)
})
Expand Down
File renamed without changes.
4 changes: 4 additions & 0 deletions src/frontend/cypress_prod.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"baseUrl": "http://localhost:8081",
"video": false
}
6 changes: 4 additions & 2 deletions src/frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@
"serve": "vue-cli-service serve",
"build": "vue-cli-service build",
"lint": "vue-cli-service lint",
"test": "cypress run --browser=firefox --headless",
"test:open": "cypress open"
"test": "cypress run --browser=firefox --headless --config-file=cypress_prod.json",
"test:prod": "cypress run --browser=firefox --headless --config-file=cypress_prod.json",
"test:dev": "cypress run --browser=firefox --headless --config-file=cypress_dev.json",
"test:open": "cypress open --config-file=cypress_dev.json"
},
"dependencies": {
"axios": "^0.21.1",
Expand Down

0 comments on commit 460df58

Please sign in to comment.