diff --git a/internal/nodejs/node.go b/internal/nodejs/node.go index f0a91085..3492bd4f 100644 --- a/internal/nodejs/node.go +++ b/internal/nodejs/node.go @@ -4,6 +4,7 @@ package nodejs import ( "bytes" "embed" + "encoding/json" "text/template" "github.com/zeabur/zbpack/pkg/packer" @@ -21,6 +22,9 @@ type TemplateContext struct { OutputDir string SPA bool Bun bool + + // ZeaburConfig is the content of .zeabur/output/config.json + ZeaburConfig string } //go:embed templates @@ -79,6 +83,32 @@ func getContextBasedOnMeta(meta types.PlanMeta) TemplateContext { context.SPA = isNotMpaFramework(meta["framework"]) } + type ZeaburConfigRoute struct { + Src string `json:"src"` + Dest string `json:"dest"` + } + + type ZeaburConfig struct { + Routes []ZeaburConfigRoute `json:"routes"` + Containerized bool `json:"containerized"` + } + + cfg := ZeaburConfig{ + Routes: []ZeaburConfigRoute{}, + Containerized: true, + } + + if context.OutputDir != "" { + cfg.Containerized = false + } + + if context.SPA { + cfg.Routes = []ZeaburConfigRoute{{Src: ".*", Dest: "/index.html"}} + } + + configStr, _ := json.Marshal(cfg) + context.ZeaburConfig = string(configStr) + return context } diff --git a/internal/nodejs/templates/nginx-runtime.Dockerfile b/internal/nodejs/templates/nginx-runtime.Dockerfile index 9b78f6c1..484997aa 100644 --- a/internal/nodejs/templates/nginx-runtime.Dockerfile +++ b/internal/nodejs/templates/nginx-runtime.Dockerfile @@ -13,4 +13,5 @@ RUN echo "\ {{ end }} } \ }"> /etc/nginx/conf.d/default.conf EXPOSE 8080 +{{ if .ZeaburConfig }}RUN echo '{{ .ZeaburConfig }}' > /src/.zeabur/output/config.json{{ end }} {{end}}