Wakeonlan Web App built with golang, sveltekit and pocketbase
wol-web
A web app hosted locally for wakeonlan>
This is a rewrite with sveltekit + PocketBase to replace the old version I wrote a few years ago>
In the new rewrite, instead of writing an entire rest API server and manage database with gorm, I use PocketBase as backend and database. Its golang extension feature allows me to add the wakeonlan feature easily. The most complicated part, Auth, is also fully handled by PocketBase, saving lots of time. PocketBase also has a built-in database management UI, making user creation/management much easier.

Deployment (Docker)
Deployment with docker is super simple.
Docker image huakunshen/wol is available on docker hub.
Both linux/amd64 and linux/arm64 are supported.
[!IMPORTANT]
1. The container must be in the same network as the target hosts
2. The container must be started with --network=host
3. Mac doesn't support --network=host with docker. On Mac you have to run server with go directly. It's recommended to use linux.
Step 1: Start Server
Here is a full command to start the server with a superuser initialized
docker run --rm \
--network=host \
-e PORT=8090 \
-e SUPERUSER_EMAIL=<root@example.com> \
-e SUPERUSER_PASSWORD=<your password> \
-v ./pbdata:/app/pbdata \
huakunshen/wol:latest
- In this example I used
--rmto clean up the container after it's closed for demo purpose - In production, you should replace
--rmwith-dto run it in detach mode
- The volume is for data persistence, so you don't lose your data after container is destroyed.
PORTenvironment variable is used to specify the port the server listens on
-p option; thus the PORT environment variable can be used to change the port.
- The 2 environment variables are used to create an initial superuser in database
users collection/table.
- When both SUPERUSEREMAIL and SUPERUSERPASSWORD are set, the server will create this superuser the first time it starts and you could login directly.
- If you didn't set initial superuser credentials, you could also create a superuser
- A long URL should be printed to console, open it in browser. The token in the URL allows you to create a superuser
(!) Launch the URL below in the browser if it hasn't been open already to create your first superuser account:
http://0.0.0.0:8090/_/#/pbinstal/eyJhbGciOiJIUzI1NiIs...
- If you ran docker run -d in detach mode, run docker logs <container name> to find the long URL for superuser creation.
Step 2: Create a Regular User
The superuser we discussed previously is like a database admin, you need to create a regular user to login to the website.
- Go to
http://localhost:8090/_/(or the url of your environment), login with superuser credentials - Go to
userscollection, create a user, remember your email and password
Step 3: Login to WOL Web
You can go to http://localhost:8090/auth and login with your regular user credentials.
Create a host then you can wake up your computer from browser.
Deployment (docker compose)
Docker compose makes creating and destroying wol container easier.
A compose.yml is provided in this repo.
services:
wol:
image: "huakunshen/wol"
container_name: wol-web
network_mode: host
volumes:
- woldata:/app/pbdata
environment:
- SUPERUSER_EMAIL=root@example.com
- SUPERUSER_PASSWORD=changeme
- PORT=8090
volumes:
wol_data:
docker compose up
docker compose down
Develop
Prerequisite:
- Bun
- Golang
dev script will start frontend and backend together.
bun install
bun run dev # start both sveltekit dev server and golang pocketbase server
Server
The golang server is in apps/server. It's a golang pocketbase extension with some custom routes.
air # start development
go run main.go serve # start the server without hot reload
Migrations
When table is modified, run go run . migrate collections to generate a migration .go file that will be auto loaded.
Frontend
The frontend is in apps/web, written with sveltekit + @sveltejs/adapter-static.
In development, use http://localhost:5173.
Running bun run build will generate a apps/web/build directory, and will be automatically copied to apps/server/pb_public ready to be served directly by the golang server as static assets.
In production the website is accesssible at http://localhost:8090/.
Docker
make buildx automatically builds docker image for linux/amd64 and linux/arm64 and push to dockerhub.