3
0

Simplify test/demo webapp installation

This commit is contained in:
Denis Arh
2020-11-10 14:23:44 +01:00
parent b052f9320a
commit 9b0308f36c
5 changed files with 59 additions and 2 deletions

View File

@@ -40,7 +40,11 @@ func (s *server) MountRoutes(mm ...func(chi.Router)) {
}
func (s server) Serve(ctx context.Context) {
s.log.Info("Starting HTTP server with REST API", zap.String("address", s.httpOpt.Addr))
s.log.Info(
"Starting HTTP server with REST API",
zap.String("address", s.httpOpt.Addr),
zap.String("baseUrl", s.httpOpt.ApiBaseUrl),
)
listener, err := net.Listen("tcp", s.httpOpt.Addr)
if err != nil {

View File

@@ -56,11 +56,19 @@ func HTTP(pfix string) (o *HTTPServerOpt) {
WebappEnabled: false,
WebappBaseUrl: "/",
WebappBaseDir: "/webapp",
WebappBaseDir: "webapp/public",
WebappList: "admin,auth,messaging,compose",
}
fill(o)
if o.WebappEnabled && o.ApiEnabled && o.ApiBaseUrl == "" {
// api base URL is still on root (empty string)
// but webapps are enabled (that means, server also serves static files from WebappBaseDir)
//
// Let's be nice and move API to /api
o.ApiBaseUrl = "/api"
}
return
}

2
webapp/.gitignore vendored Normal file
View File

@@ -0,0 +1,2 @@
public
*.tar.gz

27
webapp/Makefile Normal file
View File

@@ -0,0 +1,27 @@
WGET ?= wget
WGET_FLAGS ?= -q
TAR ?= tar
TAR_FLAGS ?= -xzmok
RELEASE_PAGE ?= https://releases.cortezaproject.org/files
APPS ?= auth admin messaging compose
ALL_APPS ?= $(APPS) one
VERSION ?= unstable
PACKAGES = $(addprefix corteza-webapp-,$(addsuffix -$(VERSION).tar.gz,$(ALL_APPS)))
all: install
install: $(PACKAGES)
mkdir -p $(addprefix public/,$(APPS))
$(TAR) $(TAR_FLAGS) -f corteza-webapp-one-$(VERSION).tar.gz -C public
$(TAR) $(TAR_FLAGS) -f corteza-webapp-auth-$(VERSION).tar.gz -C public/auth
$(TAR) $(TAR_FLAGS) -f corteza-webapp-admin-$(VERSION).tar.gz -C public/admin
$(TAR) $(TAR_FLAGS) -f corteza-webapp-messaging-$(VERSION).tar.gz -C public/messaging
$(TAR) $(TAR_FLAGS) -f corteza-webapp-compose-$(VERSION).tar.gz -C public/compose
download: $(PACKAGES)
$(PACKAGES):
$(WGET) $(WGET_FLAGS) $(RELEASE_PAGE)/$(@)
clean:
rm -f $(PACKAGES)

16
webapp/README.adoc Normal file
View File

@@ -0,0 +1,16 @@
= Web applications
Rationale behind `/webapp/...` tools is to allow backend developers to quicky test server with frontend applications.
Tools (see Makefile) download and install unstable (can be changed with `VERSION` var).
.Downloads and installs unstable packages under webapp/public
[source,shell]
----
make
----
To enable serving of webapps from the server, make sure `HTTP_WEBAPP_ENABLED` is set to `true`.
This will prefix all API endpoints with `/api/`.
See `HTTP_API_BASE_URL`, `HTTP_WEBAPP_ENABLED`, `HTTP_WEBAPP_BASE_URL`, `HTTP_WEBAPP_BASE_DIR`, `HTTP_WEBAPP_LIST` for
details