Skip to content

Commit 460df58

Browse files
authored
Merge pull request #6 from jsnjack/go116
Use go:embed
2 parents bd9369b + 8fd2c78 commit 460df58

File tree

11 files changed

+41
-59
lines changed

11 files changed

+41
-59
lines changed

.vscode/settings.json

+4-3
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
"source.fixAll.eslint": true
1111
},
1212
"eslint.workingDirectories": ["src/frontend/"],
13-
"go.languageServerExperimentalFeatures": {
14-
"rename": true
15-
},
13+
"gopls": {
14+
"buildFlags": ["-tags=wireinject"],
15+
"experimentalWorkspaceModule": true
16+
},
1617
}

Makefile

+5-17
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,14 @@ export VUE_APP_VERSION = ${VERSION}-${VUE_VERSION_SUFFIX}
1616
.ONESHELL:
1717
src/backend/wakeci: version src/backend/*.go
1818
cd src/backend
19-
rm -f rice-box.go
20-
go build -ldflags="-X main.Version=${VERSION}" -o ${BINARY}
19+
rm -rf assets
20+
cp -r ../frontend/dist/ assets
21+
CGO_ENABLED=0 go build -ldflags="-X main.Version=${VERSION}" -o ${BINARY}
2122

2223
.ONESHELL:
23-
bin/wakeci: version src/backend/*.go
24+
bin/wakeci: src/backend/wakeci
2425
cd src/backend
25-
rm -f rice-box.go
26-
rice embed-go || exit 1
27-
CGO_ENABLED=0 go build -ldflags="-X main.Version=${VERSION}" -o ${BINARY}
28-
mv wakeci ${PWD}/bin/
26+
cp wakeci ${PWD}/bin/
2927

3028
runf:
3129
cd src/frontend && npm run serve
@@ -41,16 +39,6 @@ buildf:
4139

4240
build: buildf bin/wakeci
4341

44-
deploy: build
45-
ssh wakeci mkdir wakedir
46-
ssh wakeci mkdir wakeconfig
47-
ssh wakeci sudo systemctl stop ${BINARY} || exit 0
48-
ssh wakeci rm -f ${BINARY}
49-
scp bin/${BINARY} wakeci:~/
50-
ssh wakeci sudo setcap cap_net_bind_service=+ep ${BINARY}
51-
ssh wakeci sudo systemctl start ${BINARY}
52-
ssh wakeci sudo systemctl status ${BINARY}
53-
5442
release: build
5543
grm release jsnjack/wakeci -f bin/${BINARY} -t "v`monova`"
5644

README.md

-5
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,3 @@ jobdir: ./
7777
### API documentation
7878
See full description [here](https://github.com/jsnjack/wakeci/blob/master/API.md)
7979

80-
### For developers
81-
#### Build dependencies
82-
```bash
83-
sudo dnf install golang-github-geertjohan-rice
84-
```

src/backend/.gitignore

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
wakeci
2-
vendor/
3-
rice-box.go
2+
assets

src/backend/go.mod

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
module wakeci
22

3-
go 1.13
3+
go 1.16
44

55
require (
6-
github.com/GeertJohan/go.rice v1.0.2
76
github.com/NYTimes/gziphandler v1.1.1
87
github.com/bmatcuk/doublestar v1.3.4
9-
github.com/daaku/go.zipexe v1.0.1 // indirect
8+
github.com/davecgh/go-spew v1.1.1 // indirect
109
github.com/go-cmd/cmd v1.2.0 // indirect
1110
github.com/gofrs/uuid v4.0.0+incompatible
1211
github.com/gorilla/websocket v1.4.2

src/backend/go.sum

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

src/backend/main.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package main
22

33
import (
44
"crypto/tls"
5+
"embed"
56
"flag"
67
"log"
78
"net/http"
@@ -10,7 +11,6 @@ import (
1011
"golang.org/x/crypto/acme/autocert"
1112
"golang.org/x/crypto/bcrypt"
1213

13-
rice "github.com/GeertJohan/go.rice"
1414
"github.com/NYTimes/gziphandler"
1515
"github.com/julienschmidt/httprouter"
1616
"github.com/robfig/cron/v3"
@@ -134,9 +134,10 @@ func main() {
134134
HostPolicy: autocert.HostWhitelist(Config.Hostname),
135135
}
136136

137-
vueBox := rice.MustFindBox("../frontend/dist/").HTTPBox()
137+
//go:embed assets/*
138+
var assets embed.FS
138139

139-
vuefs := http.FileServer(vueBox)
140+
vuefs := http.FileServer(http.FS(assets))
140141
storageServer := http.FileServer(http.Dir(Config.WorkDir + "wakespace"))
141142
// Configure routes
142143
router := httprouter.New()

src/backend/middleware.go

+17-13
Original file line numberDiff line numberDiff line change
@@ -151,25 +151,29 @@ func VueResourcesMi(h http.Handler) http.Handler {
151151
if !ok {
152152
logger = Logger
153153
}
154-
// First check if it is any of API or AUTH calls
155-
if strings.HasPrefix(r.URL.Path, "/api/") || strings.HasPrefix(r.URL.Path, "/auth/") {
156-
w.WriteHeader(http.StatusNotFound)
157-
logger.Printf("vue 404 %s\n", r.URL.Path)
154+
// First check if it is any of API, AUTH or STORAGE calls. This urls
155+
// should never reach this point
156+
switch {
157+
case strings.HasPrefix(r.URL.Path, "/api/"), strings.HasPrefix(r.URL.Path, "/auth/"), strings.HasPrefix(r.URL.Path, "/storage/"):
158+
w.WriteHeader(http.StatusInternalServerError)
159+
logger.Printf("vue 500 %s\n", r.URL.Path)
158160
return
159161
}
160-
// Static file or root address
161-
if strings.Contains(r.URL.Path, ".") || r.URL.Path == "/" {
162-
logger.Printf("vue GET %s\n", r.URL.Path)
163-
h.ServeHTTP(w, r)
164-
return
165-
}
166-
// Most likely this is request to one of the dynamic URLs used by frontend,
167-
// serve index.html (/) in this case
162+
168163
r2 := new(http.Request)
169164
*r2 = *r
170165
r2.URL = new(url.URL)
171166
*r2.URL = *r.URL
172-
r2.URL.Path = "/"
167+
switch {
168+
case strings.Contains(r.URL.Path, "."), r.URL.Path == "/":
169+
// Static file or root address
170+
r2.URL.Path = "/assets" + r.URL.Path
171+
break
172+
default:
173+
// Most likely this is request to one of the dynamic URLs used by frontend,
174+
// serve index.html (/assets/) in this case
175+
r2.URL.Path = "/assets/"
176+
}
173177
logger.Printf("vue %s --> %s\n", r.URL.Path, r2.URL.Path)
174178
h.ServeHTTP(w, r2)
175179
})
File renamed without changes.

src/frontend/cypress_prod.json

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"baseUrl": "http://localhost:8081",
3+
"video": false
4+
}

src/frontend/package.json

+4-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@
66
"serve": "vue-cli-service serve",
77
"build": "vue-cli-service build",
88
"lint": "vue-cli-service lint",
9-
"test": "cypress run --browser=firefox --headless",
10-
"test:open": "cypress open"
9+
"test": "cypress run --browser=firefox --headless --config-file=cypress_prod.json",
10+
"test:prod": "cypress run --browser=firefox --headless --config-file=cypress_prod.json",
11+
"test:dev": "cypress run --browser=firefox --headless --config-file=cypress_dev.json",
12+
"test:open": "cypress open --config-file=cypress_dev.json"
1113
},
1214
"dependencies": {
1315
"axios": "^0.21.1",

0 commit comments

Comments
 (0)