Files
adamfandClaude Opus 5.5 67cb8137f9
Test and publish / test (push) Successful in 6m39s
Test and publish / publish (push) Failing after 0s
Split the job tracker out of web_server into its own app
The applications tracker, leads inbox, email pipeline and capture userscript
move here from web_server's backend, Python service and Vue app, as one Go
binary that serves its own Vue SPA under /jobs/.

- The Go services, resolvers and tests move over almost unchanged.
- The three Claude calls are ported from Python to Go (internal/claude),
  with the same prompts, per-model request shaping and error messages.
- There is no login: internal/auth asks the site backend's
  /auth/validate-admin with the visitor's cookies, and relays refreshed
  cookies back.
- A Settings page replaces the admin-panel capture token card and adds the
  Microsoft sign-in link and a manual email sync.
- The userscript is 2.0.0, at /jobs/, and migrates a saved API base.
- Dockerfile, a standalone compose with Postgres, Makefile, and a Gitea CI
  workflow that tests and publishes the image.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-14 16:24:16 +01:00

66 lines
2.0 KiB
Go

package handlers
import (
"net/http"
"os"
"path"
"path/filepath"
"strings"
"github.com/gin-gonic/gin"
)
// SPA serves the built Vue app from dir for every GET under base that no API
// route claimed. It is installed as gin's NoRoute handler rather than as a
// base+"/*path" route because gin will not let a catch-all sit beside the
// /api routes at the same level.
//
// History-mode routing means a path such as /jobs/leads is a page of the app,
// not a file, so anything that is not a file in dir gets index.html — except
// under /api/ and /assets/, where a miss is a real 404: an API typo should
// not come back as a page of HTML, and neither should a stale asset hash.
//
// Caching: Vite fingerprints everything under assets/, so those are cached
// for a year; index.html is never cached, so a deploy is picked up on the
// next load.
func SPA(dir, base string) gin.HandlerFunc {
return func(ctx *gin.Context) {
p := ctx.Request.URL.Path
if ctx.Request.Method != http.MethodGet && ctx.Request.Method != http.MethodHead {
ctx.JSON(http.StatusNotFound, gin.H{"error": "not found"})
return
}
if p == base {
ctx.Redirect(http.StatusMovedPermanently, base+"/")
return
}
rel, ok := strings.CutPrefix(p, base+"/")
if !ok || strings.HasPrefix(rel, "api/") {
ctx.JSON(http.StatusNotFound, gin.H{"error": "not found"})
return
}
// path.Clean on a rooted path cannot climb above the root, so the
// result always stays inside dir.
rel = strings.TrimPrefix(path.Clean("/"+rel), "/")
if rel != "" {
file := filepath.Join(dir, filepath.FromSlash(rel))
if info, err := os.Stat(file); err == nil && !info.IsDir() {
if strings.HasPrefix(rel, "assets/") {
ctx.Header("Cache-Control", "public, max-age=31536000, immutable")
} else {
ctx.Header("Cache-Control", "no-cache")
}
ctx.File(file)
return
}
if strings.HasPrefix(rel, "assets/") {
ctx.Status(http.StatusNotFound)
return
}
}
ctx.Header("Cache-Control", "no-cache")
ctx.File(filepath.Join(dir, "index.html"))
}
}