Skip to content

Commit

Permalink
feat(lib): Add zeabur config in static output
Browse files Browse the repository at this point in the history
  • Loading branch information
yuaanlin committed Sep 14, 2023
1 parent 3cdf7c8 commit 8af7914
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
30 changes: 30 additions & 0 deletions internal/nodejs/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package nodejs
import (
"bytes"
"embed"
"encoding/json"
"text/template"

"github.com/zeabur/zbpack/pkg/packer"
Expand All @@ -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
Expand Down Expand Up @@ -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
}

Expand Down
1 change: 1 addition & 0 deletions internal/nodejs/templates/nginx-runtime.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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}}

0 comments on commit 8af7914

Please sign in to comment.