CI / go (Media) (push) Successful in 14m33s
CI / go (Server) (push) Failing after 23m30s
CI / go (Web-App) (push) Canceled after 0s
CI / frontend (push) Failing after 9m30s
CI / desktop (ubuntu-latest) (push) Successful in 1h21m24s
CI / mobile (push) Failing after 4m16s
CI / docker (push) Successful in 1h1m25s
Docs / build (push) Successful in 14m59s
Docs / deploy (push) Skipped
CI / desktop (macos-latest) (push) Canceled after 0s
CI / desktop (windows-latest) (push) Canceled after 0s
Phase G of docs/AFFINE.md (ADR-17): - Invite links: one per workspace (member or guest, optional end date, optional admin approval) on a new /join page. Requests are approved (optionally as another role) or declined from workspace settings; join_request, join_approved and join_declined notifications reach the inbox, phones and the email digest. Workspace admins decide, else the organization's admins, else superadmins. Signup honours ?redirect=. - Workspace switches: allowSharing (off makes every share link answer 404 until it is back on) and urlPreview (chat apps may show private pages' titles). docwell-web writes title and Open Graph tags for known link-preview bots, asking docwell-server via DOCWELL_PREVIEW_API_URL; search engines are left out. - Page analytics: page_views counts opens per page, person and day from the existing visit call and share-link reads; editors see totals, a daily chart and recent viewers in the Info panel. analytics.prune drops rows after 400 days. - Unused files: attachments whose id appears in no page's Yjs state, page icon or comment (older than a day) are listed and deleted from workspace settings. - Migration, schema snapshot, OpenAPI, generated clients, translations in five languages, phone inbox, compose files and user docs. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
90 lines
2.2 KiB
Go
90 lines
2.2 KiB
Go
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
|
|
// Command docwell-web serves the Docwell web app.
|
|
package main
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"log/slog"
|
|
"net/http"
|
|
"net/url"
|
|
"os"
|
|
"os/signal"
|
|
"syscall"
|
|
"time"
|
|
|
|
"docwell/web/internal/spa"
|
|
)
|
|
|
|
// Version is set at build time with -ldflags "-X main.Version=...".
|
|
var Version = "dev"
|
|
|
|
func env(key, def string) string {
|
|
if v := os.Getenv(key); v != "" {
|
|
return v
|
|
}
|
|
return def
|
|
}
|
|
|
|
func main() {
|
|
log := slog.New(slog.NewJSONHandler(os.Stdout, nil))
|
|
if err := run(log); err != nil {
|
|
log.Error("fatal", "err", err)
|
|
os.Exit(1)
|
|
}
|
|
}
|
|
|
|
func run(log *slog.Logger) error {
|
|
addr := env("DOCWELL_WEB_ADDR", ":3000")
|
|
|
|
opts := spa.Options{Config: spa.RuntimeConfig{
|
|
APIURL: env("DOCWELL_API_URL", "http://localhost:8080"),
|
|
CollabURL: env("DOCWELL_COLLAB_URL", "ws://localhost:8080/collab"),
|
|
DrawioURL: env("DOCWELL_DRAWIO_URL", ""),
|
|
Version: Version,
|
|
}}
|
|
if target := os.Getenv("DOCWELL_PROXY_TARGET"); target != "" {
|
|
u, err := url.Parse(target)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
opts.ProxyTarget = u
|
|
// With the proxy on, the browser talks to this origin only.
|
|
opts.Config.APIURL = ""
|
|
opts.Config.CollabURL = ""
|
|
}
|
|
// Link previews for chat apps ask docwell-server directly: through
|
|
// DOCWELL_PREVIEW_API_URL, else the proxy target, else the public API URL.
|
|
previewAPI := env("DOCWELL_PREVIEW_API_URL", os.Getenv("DOCWELL_PROXY_TARGET"))
|
|
if previewAPI == "" {
|
|
previewAPI = env("DOCWELL_API_URL", "http://localhost:8080")
|
|
}
|
|
if u, err := url.Parse(previewAPI); err == nil && (u.Scheme == "http" || u.Scheme == "https") {
|
|
opts.PreviewAPI = u
|
|
}
|
|
|
|
srv := &http.Server{Addr: addr, Handler: spa.Handler(opts), ReadHeaderTimeout: 10 * time.Second}
|
|
|
|
ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM)
|
|
defer stop()
|
|
|
|
errCh := make(chan error, 1)
|
|
go func() {
|
|
log.Info("docwell-web listening", "addr", addr, "version", Version)
|
|
errCh <- srv.ListenAndServe()
|
|
}()
|
|
|
|
select {
|
|
case err := <-errCh:
|
|
if !errors.Is(err, http.ErrServerClosed) {
|
|
return err
|
|
}
|
|
case <-ctx.Done():
|
|
}
|
|
|
|
shutdownCtx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
|
defer cancel()
|
|
return srv.Shutdown(shutdownCtx)
|
|
}
|