Skip to content

Getting Started

This section will help you bring spa-server up, and upload your static web files to it.

Run spa-server by docker

uploading file feature needs spa-server open admin-server. So we should create a config file first.

bash
$ echo '
file_dir = "/data"

[http]
port = 8080
addr = "0.0.0.0"

[admin_config]
port = 9000
addr = "0.0.0.0"  
token = "token"
' > config.toml

$ docker run -it -p 8080 -p 9000 -v $(pwd)/config.toml:/config.toml \
ghcr.io/fornetcode/spa-server:latest

Run spa-client in npm project

  1. Install spa-client npm package.
shell
npm install spa-client dotenv --save-dev
  1. add config for spa-client in the .env file
# all config start with `SPA` for spa-client
SPA_SERVER_ADDRESS=http://127.0.0.1:9000

SPA_SERVER_AUTH_TOKEN=token

# upload file parallel number, optional, default is 3
SPA_UPLOAD_PARALLEL=3
  1. Add script to package.json (need dotenv). www.example.com is the domain of your website, and ./build is directory of static web files.
json
{
  "script": {
    "upload": "dotenv .env spa-client upload ./build www.example.com",
    "release": "dotenv .env spa-client release www.example.com"
  }
}

we also support serving multiple SPA in one domain:

json
{
  "script": {
    "upload1": "dotenv .env spa-client upload ./build www.example.com/a",
    "release1": "dotenv .env spa-client release www.example.com/a",
    "upload2": "dotenv .env spa-client upload ./build www.example.com/b",
    "release2": "dotenv .env spa-client release www.example.com/b"
  }
}

What's More