aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cmd/frontend/main.go18
-rw-r--r--cmd/pkgsite/main.go1
-rw-r--r--internal/frontend/fetchserver/fetch_test.go1
-rw-r--r--internal/frontend/frontend_test.go1
-rw-r--r--internal/frontend/server.go19
5 files changed, 17 insertions, 23 deletions
diff --git a/cmd/frontend/main.go b/cmd/frontend/main.go
index 2a05e14c..13324a3c 100644
--- a/cmd/frontend/main.go
+++ b/cmd/frontend/main.go
@@ -32,6 +32,7 @@ import (
"golang.org/x/pkgsite/internal/queue"
"golang.org/x/pkgsite/internal/queue/gcpqueue"
"golang.org/x/pkgsite/internal/source"
+ "golang.org/x/pkgsite/internal/static"
"golang.org/x/pkgsite/internal/vuln"
)
@@ -115,6 +116,22 @@ func main() {
log.Fatalf(ctx, "vuln.NewClient: %v", err)
}
staticSource := template.TrustedSourceFromFlag(flag.Lookup("static").Value)
+ if *devMode {
+ // In dev mode compile TypeScript files into minified JavaScript files
+ // and rebuild them on file changes.
+ if *staticFlag == "" {
+ panic("staticPath is empty in dev mode; cannot rebuild static files")
+ }
+ ctx := context.Background()
+ if err := static.Build(static.Config{
+ EntryPoint: *staticFlag + "/frontend",
+ Watch: true,
+ Bundle: true,
+ }); err != nil {
+ log.Error(ctx, err)
+ }
+ }
+
// TODO: Can we use a separate queue for the fetchServer and for the Server?
// It would help differentiate ownership.
fetchServer := &fetchserver.FetchServer{
@@ -128,7 +145,6 @@ func main() {
Queue: fetchQueue,
TemplateFS: template.TrustedFSFromTrustedSource(staticSource),
StaticFS: os.DirFS(*staticFlag),
- StaticPath: *staticFlag,
ThirdPartyFS: os.DirFS(*thirdPartyPath),
DevMode: *devMode,
LocalMode: *localMode,
diff --git a/cmd/pkgsite/main.go b/cmd/pkgsite/main.go
index 9bf74930..9f5eaefd 100644
--- a/cmd/pkgsite/main.go
+++ b/cmd/pkgsite/main.go
@@ -427,7 +427,6 @@ func newServer(getters []fetch.ModuleGetter, localModules []frontend.LocalModule
DevMode: *devMode,
LocalMode: true,
LocalModules: localModules,
- StaticPath: *staticFlag,
ThirdPartyFS: thirdparty.FS,
})
if err != nil {
diff --git a/internal/frontend/fetchserver/fetch_test.go b/internal/frontend/fetchserver/fetch_test.go
index a4eb381c..c98585df 100644
--- a/internal/frontend/fetchserver/fetch_test.go
+++ b/internal/frontend/fetchserver/fetch_test.go
@@ -70,7 +70,6 @@ func newTestServerWithFetch(t *testing.T, proxyModules []*proxytest.Module, cach
// Integration tests will use the actual directories.
StaticFS: static.FS,
ThirdPartyFS: thirdparty.FS,
- StaticPath: "../../static",
})
if err != nil {
t.Fatal(err)
diff --git a/internal/frontend/frontend_test.go b/internal/frontend/frontend_test.go
index c43257b3..2fe64269 100644
--- a/internal/frontend/frontend_test.go
+++ b/internal/frontend/frontend_test.go
@@ -48,7 +48,6 @@ func newTestServer(t *testing.T, cacher Cacher) (*Server, http.Handler) {
// Integration tests will use the actual directories.
StaticFS: static.FS,
ThirdPartyFS: thirdparty.FS,
- StaticPath: "../../static",
})
if err != nil {
t.Fatal(err)
diff --git a/internal/frontend/server.go b/internal/frontend/server.go
index 264669b8..c0df2168 100644
--- a/internal/frontend/server.go
+++ b/internal/frontend/server.go
@@ -35,7 +35,6 @@ import (
"golang.org/x/pkgsite/internal/memory"
"golang.org/x/pkgsite/internal/middleware/stats"
"golang.org/x/pkgsite/internal/queue"
- "golang.org/x/pkgsite/internal/static"
"golang.org/x/pkgsite/internal/version"
"golang.org/x/pkgsite/internal/vuln"
"golang.org/x/text/cases"
@@ -54,7 +53,6 @@ type Server struct {
devMode bool
localMode bool // running locally (i.e. ./cmd/pkgsite)
localModules []LocalModule // locally hosted modules; empty in production
- staticPath string // used only for dynamic loading in dev mode
errorPage []byte
appVersionLabel string
googleTagManagerID string
@@ -95,7 +93,6 @@ type ServerConfig struct {
DevMode bool
LocalMode bool
LocalModules []LocalModule
- StaticPath string // used only for dynamic loading in dev mode
Reporter derrors.Reporter
VulndbClient *vuln.Client
}
@@ -118,7 +115,6 @@ func NewServer(scfg ServerConfig) (_ *Server, err error) {
devMode: scfg.DevMode,
localMode: scfg.LocalMode,
localModules: scfg.LocalModules,
- staticPath: scfg.StaticPath,
templates: ts,
reporter: scfg.Reporter,
fileMux: http.NewServeMux(),
@@ -738,21 +734,6 @@ func parsePageTemplates(fsys template.TrustedFS) (map[string]*template.Template,
}
func (s *Server) staticHandler() http.Handler {
- // In dev mode compile TypeScript files into minified JavaScript files
- // and rebuild them on file changes.
- if s.devMode {
- if s.staticPath == "" {
- panic("staticPath is empty in dev mode; cannot rebuild static files")
- }
- ctx := context.Background()
- if err := static.Build(static.Config{
- EntryPoint: s.staticPath + "/frontend",
- Watch: true,
- Bundle: true,
- }); err != nil {
- log.Error(ctx, err)
- }
- }
return http.StripPrefix("/static/", http.FileServer(http.FS(s.staticFS)))
}