diff options
| author | Shulhan <ms@kilabit.info> | 2024-07-08 00:25:11 +0700 |
|---|---|---|
| committer | Shulhan <ms@kilabit.info> | 2024-07-15 00:36:07 +0700 |
| commit | e6c6a89ef014bef56d1078fcc622038d35ee2354 (patch) | |
| tree | 973072f71ba632ff6585362bc03d469e389d7b93 | |
| parent | ac0c21615e9dc457995ab5bcb7161cf545887152 (diff) | |
| download | rescached-e6c6a89ef014bef56d1078fcc622038d35ee2354.tar.xz | |
internal/cmd/www: an HTTP server for testing web UI
The web user interface can be run using existing rescached server by
setting the SERVER value in class Rescached (_www/rescached.js).
| -rw-r--r-- | .gitignore | 1 | ||||
| -rw-r--r-- | Makefile | 11 | ||||
| -rw-r--r-- | _www/rescached.js | 19 | ||||
| -rw-r--r-- | internal/cmd/www/main.go | 44 |
4 files changed, 65 insertions, 10 deletions
@@ -1,3 +1,4 @@ +/CHANGELOG.html /README.html /TODO /_bin/darwin_amd64 @@ -75,9 +75,9 @@ lint: -shadow ./... -golangci-lint run \ --presets bugs,metalinter,performance,unused \ + --disable bodyclose \ --disable exhaustive \ --disable musttag \ - --disable bodyclose \ ./... -reuse --suppress-deprecation lint @@ -222,3 +222,12 @@ build-linux-amd64: build deploy-personal-server: build-linux-amd64 rsync --progress _bin/linux_amd64/rescached personal-server:~/bin/rescached ssh personal-server "sudo rsync ~/bin/rescached /usr/bin/rescached; sudo systemctl restart rescached.service" + + +#---- Development. + +## Run web server to test WUI. + +.PHONY: dev.www +dev.www: + go run ./internal/cmd/www diff --git a/_www/rescached.js b/_www/rescached.js index cdfa4c3..a3fdbf5 100644 --- a/_www/rescached.js +++ b/_www/rescached.js @@ -39,21 +39,22 @@ function getRRTypeName(k) { } class Rescached { + static SERVER = ""; static nanoSeconds = 1000000000; - static apiBlockd = "/api/block.d"; - static apiBlockdFetch = "/api/block.d/fetch"; + static apiBlockd = Rescached.SERVER + "/api/block.d"; + static apiBlockdFetch = Rescached.SERVER + "/api/block.d/fetch"; - static apiCaches = "/api/caches"; - static apiCachesSearch = "/api/caches/search"; + static apiCaches = Rescached.SERVER + "/api/caches"; + static apiCachesSearch = Rescached.SERVER + "/api/caches/search"; - static apiEnvironment = "/api/environment"; + static apiEnvironment = Rescached.SERVER + "/api/environment"; - static apiHostsd = "/api/hosts.d"; - static apiHostsdRR = "/api/hosts.d/rr"; + static apiHostsd = Rescached.SERVER + "/api/hosts.d"; + static apiHostsdRR = Rescached.SERVER + "/api/hosts.d/rr"; - static apiZoned = "/api/zone.d"; - static apiZonedRR = "/api/zone.d/rr"; + static apiZoned = Rescached.SERVER + "/api/zone.d"; + static apiZonedRR = Rescached.SERVER + "/api/zone.d/rr"; constructor(server) { this.blockd = {}; diff --git a/internal/cmd/www/main.go b/internal/cmd/www/main.go new file mode 100644 index 0000000..22b384b --- /dev/null +++ b/internal/cmd/www/main.go @@ -0,0 +1,44 @@ +// SPDX-FileCopyrightText: 2024 M. Shulhan <ms@kilabit.info> +// SPDX-License-Identifier: GPL-3.0-or-later + +// Package www provides an HTTP server that serve the _www directory for +// testing. +// The web user interface can be run using existing rescached server by +// setting the SERVER value in class Rescached (_www/rescached.js). +package main + +import ( + "flag" + "log" + + "git.sr.ht/~shulhan/ciigo" + "git.sr.ht/~shulhan/pakakeh.go/lib/memfs" +) + +func main() { + var flagAddress string + + flag.StringVar(&flagAddress, `address`, `127.0.0.1:6200`, `Listen address`) + + flag.Parse() + + var serveOpts = ciigo.ServeOptions{ + Mfs: &memfs.MemFS{ + Opts: &memfs.Options{ + Root: `./_www`, + TryDirect: true, + }, + }, + ConvertOptions: ciigo.ConvertOptions{ + Root: `./_www`, + HTMLTemplate: `./_www/doc/html.tmpl`, + }, + Address: flagAddress, + IsDevelopment: true, + } + + var err = ciigo.Serve(&serveOpts) + if err != nil { + log.Fatal(err) + } +} |
