Skip to content

Commit

Permalink
Fix CI, update README and change build tag option
Browse files Browse the repository at this point in the history
  • Loading branch information
prasunanand committed Jan 18, 2025
1 parent d08a322 commit a1efa14
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 87 deletions.
9 changes: 6 additions & 3 deletions .github/workflows/electron-mac.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,6 @@ jobs:
run: |
brew update
brew install zeromq
- name: Build
run: go build -tags webapp -o ui/public/zasper
- name: Set up Node.js
uses: actions/setup-node@v4
Expand All @@ -39,6 +36,12 @@ jobs:
- name: Install dependencies
run: cd ui && npm install

- name: Build Zasper Frontend
run: cd ui && npm run build

- name: Build Zasper Backend
run: go build -o ui/public/zasper

- name: Package Electron app
run: cd ui && npm run electron-package

Expand Down
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Zasper is an IDE designed from the ground up to support massive concurrency. It

It's perfectly suited for running REPL-style data applications, with Jupyter notebooks being one example.

Currently Zasper is fully supported on Mac with limited support on Linux.
**Currently Zasper is fully supported on MacOS and Linux.** Windows support is coming soon!

# Benchmarks - 4X Better
Zasper uses one fourth of RAM and one fourth of CPU used by Jupterlab. While Jupyterlab uses around 104.8 MB of RAM and 0.8 CPUs, Zasper uses 26.7 MB of RAM and 0.2 CPUs.
Expand Down Expand Up @@ -91,7 +91,7 @@ On debian
sudo apt-get install libzmq3-dev
```

On mac
On macOS
```zsh
brew install pkg-config
brew install zeromq
Expand All @@ -101,7 +101,7 @@ brew install zeromq
Go to project home and start the server

```bash
go build -tags webapp -o ui/public/zasper
go build -o ui/public/zasper
```

Go to `ui` and run the app in dev mode
Expand Down Expand Up @@ -129,7 +129,7 @@ On debian
sudo apt-get install libzmq3-dev
```

On mac
On macOS
```zsh
brew install pkg-config
brew install zeromq
Expand All @@ -142,7 +142,7 @@ Install zeromq.
Go to project home and start the server

```bash
go build -tags webapp
go build
```
This will crate a binary called `zasper`. Now add this binary to your path.

Expand All @@ -156,14 +156,14 @@ Usage of ../zasper:
-debug
sets log level to debug
-port string
port to start the server on (default ":8888")
port to start the server on (default ":8048")
```


Go to any directory you want to serve and run `zasper`. This starts zasper server in the directory.
```
% zasper
2024/12/15 20:39:12 Zasper Server started! Listening on port:8888
2024/12/15 20:39:12 Zasper Server started! Listening on port:8048
███████╗ █████╗ ███████╗██████╗ ███████╗██████╗
╚══███╔╝██╔══██╗██╔════╝██╔══██╗██╔════╝██╔══██╗
Expand Down
50 changes: 34 additions & 16 deletions spa.go
Original file line number Diff line number Diff line change
@@ -1,43 +1,61 @@
//go:build !webapp
// +build !webapp
//go:build !apiserver
// +build !apiserver

package main

import (
"embed"
"io/fs"
"net/http"
"os"
"path/filepath"
)

//go:embed ui/build/*

Check failure on line 14 in spa.go

View workflow job for this annotation

GitHub Actions / build

pattern ui/build/*: no matching files found
var staticFiles embed.FS

type spaHandler struct {
staticFS embed.FS
staticPath string
indexPath string
}

// no longer used, will be helpful in Zasperhub in future when running api only server
func (h spaHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
// Join internally call path.Clean to prevent directory traversal
path := filepath.Join(h.staticPath, r.URL.Path)

// check whether a file exists or is a directory at the given path
fi, err := os.Stat(path)
if os.IsNotExist(err) || fi.IsDir() {
// file does not exist or path is a directory, serve index.html
http.ServeFile(w, r, filepath.Join(h.staticPath, h.indexPath))
// get the absolute path to prevent directory traversal
path, err := filepath.Abs(r.URL.Path)
if err != nil {
// if we failed to get the absolute path respond with a 400 bad request and stop
http.Error(w, err.Error(), http.StatusBadRequest)
return
}

if err != nil {
// prepend the path with the path to the static directory
path = filepath.Join(h.staticPath, path)

_, err = h.staticFS.Open(path)
if os.IsNotExist(err) {
// file does not exist, serve index.html
index, err := h.staticFS.ReadFile(filepath.Join(h.staticPath, h.indexPath))
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
w.Header().Set("Content-Type", "text/html; charset=utf-8")
w.WriteHeader(http.StatusAccepted)
w.Write(index)
return
} else if err != nil {
// if we got an error (that wasn't that the file doesn't exist) stating the
// file, return a 500 internal server error and stop
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}

// otherwise, use http.FileServer to serve the static file
http.FileServer(http.Dir(h.staticPath)).ServeHTTP(w, r)
// get the subdirectory of the static dir
statics, err := fs.Sub(h.staticFS, h.staticPath)
// otherwise, use http.FileServer to serve the static dir
http.FileServer(http.FS(statics)).ServeHTTP(w, r)
}

func getSpaHandler() http.Handler {
return spaHandler{staticPath: "./ui/build", indexPath: "index.html"}
return spaHandler{staticFS: staticFiles, staticPath: "ui/build", indexPath: "index.html"}
}
42 changes: 42 additions & 0 deletions spa_apiserver.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
//go:build apiserver
// +build apiserver

package main

import (
"net/http"
"os"
"path/filepath"
)

type spaHandler struct {
staticPath string
indexPath string
}

func (h spaHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
// Join internally call path.Clean to prevent directory traversal
path := filepath.Join(h.staticPath, r.URL.Path)

// check whether a file exists or is a directory at the given path
fi, err := os.Stat(path)
if os.IsNotExist(err) || fi.IsDir() {
// file does not exist or path is a directory, serve index.html
http.ServeFile(w, r, filepath.Join(h.staticPath, h.indexPath))
return
}

if err != nil {
// if we got an error (that wasn't that the file doesn't exist) stating the
// file, return a 500 internal server error and stop
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}

// otherwise, use http.FileServer to serve the static file
http.FileServer(http.Dir(h.staticPath)).ServeHTTP(w, r)
}

func getSpaHandler() http.Handler {
return spaHandler{staticPath: "./ui/build", indexPath: "index.html"}
}
61 changes: 0 additions & 61 deletions spa_webapp.go

This file was deleted.

0 comments on commit a1efa14

Please sign in to comment.