Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
lqqyt2423 committed Jun 27, 2024
2 parents f6ec208 + 0026f38 commit 0bccca2
Show file tree
Hide file tree
Showing 19 changed files with 40 additions and 123 deletions.
8 changes: 8 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@ jobs:
with:
fetch-depth: 0

- uses: actions/setup-node@v4
with:
node-version: 20
- run: yarn install
working-directory: web/client
- run: yarn build
working-directory: web/client

- name: Set up Go
uses: actions/setup-go@v4
with:
Expand Down
16 changes: 0 additions & 16 deletions web/client/build/asset-manifest.json

This file was deleted.

Binary file removed web/client/build/favicon.ico
Binary file not shown.
1 change: 0 additions & 1 deletion web/client/build/index.html

This file was deleted.

Binary file removed web/client/build/logo192.png
Binary file not shown.
Binary file removed web/client/build/logo512.png
Binary file not shown.
25 changes: 0 additions & 25 deletions web/client/build/manifest.json

This file was deleted.

3 changes: 3 additions & 0 deletions web/client/build/readme.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
This dir should be exist, in case go:embed client/build throw error.

//go:embed client/build
3 changes: 0 additions & 3 deletions web/client/build/robots.txt

This file was deleted.

7 changes: 0 additions & 7 deletions web/client/build/static/css/main.15b22d69.css

This file was deleted.

1 change: 0 additions & 1 deletion web/client/build/static/css/main.15b22d69.css.map

This file was deleted.

2 changes: 0 additions & 2 deletions web/client/build/static/js/496.aae294ae.chunk.js

This file was deleted.

1 change: 0 additions & 1 deletion web/client/build/static/js/496.aae294ae.chunk.js.map

This file was deleted.

3 changes: 0 additions & 3 deletions web/client/build/static/js/main.dcfaa455.js

This file was deleted.

45 changes: 0 additions & 45 deletions web/client/build/static/js/main.dcfaa455.js.LICENSE.txt

This file was deleted.

1 change: 0 additions & 1 deletion web/client/build/static/js/main.dcfaa455.js.map

This file was deleted.

This file was deleted.

2 changes: 1 addition & 1 deletion web/client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"build": "BUILD_PATH=build/dist react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
Expand Down
44 changes: 28 additions & 16 deletions web/web.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package web

import (
"embed"
"fmt"
"io/fs"
"net/http"
"sync"
Expand All @@ -16,35 +17,46 @@ var assets embed.FS

type WebAddon struct {
proxy.BaseAddon

server *http.Server
upgrader *websocket.Upgrader

conns []*concurrentConn
connsMu sync.RWMutex
}

func NewWebAddon(addr string) *WebAddon {
web := new(WebAddon)
web.upgrader = &websocket.Upgrader{
CheckOrigin: func(r *http.Request) bool {
return true
},
}

serverMux := new(http.ServeMux)
serverMux.HandleFunc("/echo", web.echo)
web := &WebAddon{}

fsys, err := fs.Sub(assets, "client/build")
_, err := assets.ReadDir("client/build/dist")
if err != nil {
panic(err)
}
serverMux.Handle("/", http.FileServer(http.FS(fsys)))
web.server = &http.Server{
Addr: addr,
Handler: http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusNotFound)
fmt.Fprintf(w, `Please build frontend: "cd web/client; yarn build"`)
}),
}
} else {
web.upgrader = &websocket.Upgrader{
CheckOrigin: func(r *http.Request) bool {
return true
},
}

serverMux := new(http.ServeMux)
serverMux.HandleFunc("/echo", web.echo)

server := &http.Server{Addr: addr, Handler: serverMux}
web.conns = make([]*concurrentConn, 0)
fsys, _ := fs.Sub(assets, "client/build/dist")
serverMux.Handle("/", http.FileServer(http.FS(fsys)))

web.server = &http.Server{Addr: addr, Handler: serverMux}
web.conns = make([]*concurrentConn, 0)
}

go func() {
log.Infof("web interface start listen at %v\n", addr)
err := server.ListenAndServe()
err := web.server.ListenAndServe()
log.Error(err)
}()

Expand Down

0 comments on commit 0bccca2

Please sign in to comment.