-
-
Notifications
You must be signed in to change notification settings - Fork 396
Build and deploy
Having a working progressive web app built with the go-app package requires 2 parts to be built.
The server is a classic Go program. It uses the Handler to serve the WebAssembly part. It is built with the standard go build command:
go buildSee the HTTP Handler topic.
The WebAssembly app part is where all the UI is implemented. It is served by the server part from the /app.wasm endpoint. Building this requires using the go build command while specifying the wasm architecture and the js operating system:
GOARCH=wasm GOOS=js go build -o app.wasmOnce built, app.wasm must be moved in the web directory, located by the side of the server binary:
. # Directory root
├── server # Server binary
├── main.go # Server source code
└── web # Directory for static resources
└── app.wasm # Wasm binary
While unit testing the server is a standard go test command, testing the WebAssembly part requires some setup.
Since the app is working on a web browser, the unit tests should run in a similar environment. Set up WebAssembly go test to run in the browser with the following command:
go get -u github.com/agnivade/wasmbrowsertest && \
mv $GOPATH/bin/wasmbrowsertest $GOPATH/bin/go_js_wasm_execIt installs wasmbrowsertest which is a program that allows go test to be executed on Chrome with headless mode. Because it uses resources bound to a specific version of Go, the command above has to be used whenever you update Go.
Then, as for the build command, the unit test can be launched by specifying the wasm architecture and the js operating system:
GOARCH=wasm GOOS=js go testFrom local machines to cloud providers, progressive web apps built with go-app can be deployed in multiple places. Refer to the demo examples to see how it can be done:
| Sources | Description |
|---|---|
| hello | Hello app. |
| hello-local | Hello app that runs on a local server. |
| hello-local-external-root | Hello app that runs on a local server but with a custom root directory. |
| hello-docker | Hello app that run in a Docker container. |
| hello-gcloud-appengine | Hello app that run on Google Cloud App Engine. See live |
| hello-gcloud-func | Hello app that run on Google a Cloud Function. See live |
