Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ help:

## build/canopy: build the canopy binary into the GO_BIN_DIR
build/canopy:
npm install --prefix $(EXPLORER_DIR) && npm run build --prefix $(EXPLORER_DIR)
go build -o $(GO_BIN_DIR)/canopy $(CLI_DIR)

## build/canopy-full: build the canopy binary and its wallet and explorer altogether
Expand Down
38 changes: 21 additions & 17 deletions cmd/rpc/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const (
ApplicationJSON = "application/json; charset=utf-8"

walletStaticDir = "web/wallet/out"
explorerStaticDir = "web/explorer/out"
explorerStaticDir = "web/explorer/dist"
)

// Server represents a Canopy RPC server with configuration options.
Expand Down Expand Up @@ -335,7 +335,7 @@ func (h logHandler) Handle(resp http.ResponseWriter, req *http.Request, p httpro
h.h(resp, req, p)
}

//go:embed all:web/explorer/out
//go:embed all:web/explorer/dist
var explorerFS embed.FS

//go:embed all:web/wallet/out
Expand All @@ -352,23 +352,13 @@ func (s *Server) runStaticFileServer(fileSys fs.FS, dir, port string, conf lib.C

// Create a new ServeMux to handle incoming HTTP requests
mux := http.NewServeMux()
fileServer := http.FileServer(http.FS(distFS))

// Define a handler function for the root path
mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
// serve `index.html` with dynamic config injection
if r.URL.Path == "/" || r.URL.Path == "/index.html" {

serveIndex := func() {
// Construct the file path for `index.html`
filePath := path.Join(dir, "index.html")

// Open the file and defer closing until the function exits
data, e := fileSys.Open(filePath)
if e != nil {
http.NotFound(w, r)
return
}
defer data.Close()

// Read the content of `index.html` into a byte slice
htmlBytes, e := fs.ReadFile(fileSys, filePath)
if e != nil {
Expand All @@ -382,12 +372,26 @@ func (s *Server) runStaticFileServer(fileSys fs.FS, dir, port string, conf lib.C
// Set the response header as HTML and write the injected content to the response
w.Header().Set("Content-Type", "text/html")
w.WriteHeader(http.StatusOK)
w.Write([]byte(injectedHTML))
_, _ = w.Write([]byte(injectedHTML))
}

// Serve `index.html` with dynamic config injection
if r.URL.Path == "/" || r.URL.Path == "/index.html" {
serveIndex()
return
}

// For all other requests, serve the files directly from the file system
http.FileServer(http.FS(distFS)).ServeHTTP(w, r)
// Serve real static assets if they exist.
requestPath := strings.TrimPrefix(path.Clean(r.URL.Path), "/")
if requestPath != "" {
if _, e := fs.Stat(distFS, requestPath); e == nil {
fileServer.ServeHTTP(w, r)
return
}
}

// SPA fallback: unknown client-side routes resolve to index.html.
serveIndex()
})

// Start the HTTP server in a new goroutine and listen on the specified port
Expand Down
7 changes: 7 additions & 0 deletions cmd/rpc/web/explorer/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
dist/
node_modules/
*.config.js
*.config.ts
vite.config.ts
postcss.config.js
tailwind.config.js
49 changes: 18 additions & 31 deletions cmd/rpc/web/explorer/.gitignore
Original file line number Diff line number Diff line change
@@ -1,37 +1,24 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
/.pnp
.pnp.js

# testing
/coverage

# next.js
/.next/
/out/

# production
/build

# misc
.DS_Store
*.pem

# debug
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*

# local env files
.env*.local

# vercel
.vercel

# typescript
*.tsbuildinfo
next-env.d.ts
node_modules
dist
dist-ssr
*.local

# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
.DS_Store
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?
1 change: 1 addition & 0 deletions cmd/rpc/web/explorer/.nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
20
8 changes: 0 additions & 8 deletions cmd/rpc/web/explorer/.prettierrc

This file was deleted.

Loading
Loading