Compare commits

...

2 Commits

Author SHA1 Message Date
7b47004cf7 Can publish to process
All checks were successful
release-nightly / build-docker (push) Successful in 1m9s
2023-12-10 18:26:04 +08:00
ccc98f6633 🐛 Body limit fixes 2023-12-10 18:15:22 +08:00
12 changed files with 36 additions and 21 deletions

View File

@ -12,14 +12,24 @@ import (
)
func doPublish(c *fiber.Ctx) error {
var upstream *sign.UpstreamConfig
var workdir string
var site *sign.SiteConfig
var upstream *sign.UpstreamConfig
var process *sign.ProcessConfig
for _, item := range sign.App.Sites {
if item.ID == c.Params("site") {
site = item
for _, stream := range item.Upstreams {
if stream.ID == c.Params("upstream") {
if stream.ID == c.Params("slug") {
upstream = stream
workdir, _ = stream.GetRawURI()
break
}
}
for _, proc := range item.Processes {
if proc.ID == c.Params("slug") {
process = proc
workdir = proc.Workdir
break
}
}
@ -27,9 +37,9 @@ func doPublish(c *fiber.Ctx) error {
}
}
if upstream == nil {
if upstream == nil && process == nil {
return fiber.ErrNotFound
} else if upstream.GetType() != sign.UpstreamTypeFile {
} else if upstream != nil && upstream.GetType() != sign.UpstreamTypeFile {
return fiber.ErrUnprocessableEntity
}
@ -37,8 +47,6 @@ func doPublish(c *fiber.Ctx) error {
process.StopProcess()
}
workdir, _ := upstream.GetRawURI()
if c.Query("overwrite", "yes") == "yes" {
files, _ := filepath.Glob(filepath.Join(workdir, "*"))
for _, file := range files {

View File

@ -19,6 +19,7 @@ func InitAdministration() *fiber.App {
EnableIPValidation: true,
EnablePrintRoutes: viper.GetBool("debug.print_routes"),
TrustedProxies: viper.GetStringSlice("security.administration_trusted_proxies"),
BodyLimit: viper.GetInt("hypertext.limitation.max_body_size"),
})
if viper.GetBool("performance.request_logging") {
@ -42,7 +43,7 @@ func InitAdministration() *fiber.App {
webhooks := app.Group("/webhooks").Name("WebHooks")
{
webhooks.Put("/publish/:site/:upstream", doPublish)
webhooks.Put("/publish/:site/:slug", doPublish)
}
return app

View File

@ -70,10 +70,10 @@ var DeployCommands = []*cli.Command{
BasicAuth("RoadSign CLI", server.Credential)
var mistake error
if status, _, err := client.Bytes(); len(err) > 0 {
if status, data, err := client.Bytes(); len(err) > 0 {
mistake = fmt.Errorf("failed to publish to remote: %q", err)
} else if status != 200 {
mistake = fmt.Errorf("server rejected request, status code %d", status)
mistake = fmt.Errorf("server rejected request, status code %d, response %s", status, string(data))
}
// Cleanup

View File

@ -20,7 +20,6 @@ func (v *ProcessConfig) BootProcess() error {
if v.Cmd != nil {
return nil
}
if err := v.PreapreProcess(); err != nil {
return err
}
@ -69,8 +68,13 @@ func (v *ProcessConfig) StartProcess() error {
func (v *ProcessConfig) StopProcess() error {
if v.Cmd != nil && v.Cmd.Process != nil {
return v.Cmd.Process.Signal(os.Interrupt)
} else {
return nil
if err := v.Cmd.Process.Signal(os.Interrupt); err != nil {
v.Cmd.Process.Kill()
return err
} else {
v.Cmd = nil
}
}
return nil
}

View File

@ -22,6 +22,8 @@ func (v *AppConfig) Forward(ctx *fiber.Ctx, site *SiteConfig) error {
if err := process.BootProcess(); err != nil {
log.Warn().Err(err).Msgf("An error occurred when booting process (%s) for %s", process.ID, site.ID)
return fiber.ErrBadGateway
} else {
log.Debug().Msg("process is alive!")
}
}

View File

@ -10,7 +10,7 @@ hypertext:
key: ./cert.key
pem: ./cert.pem
limitation:
max_body_size: -1
max_body_size: 536870912
max_qps: -1
ports:
- :8000

View File

@ -1,2 +1,2 @@
/.output
/.spa
/ssr
/spa

View File

@ -9,7 +9,7 @@ hypertext:
key: ./cert.key
pem: ./cert.pem
limitation:
max_body_size: -1
max_body_size: 536870912
max_qps: -1
ports:
- :8000

View File

@ -8,5 +8,5 @@ upstreams:
uri: http://localhost:3000
processes:
- id: nuxt-ssr
workdir: ../data
workdir: ../data/ssr
command: ["node", ".output/server/index.mjs"]

View File

@ -9,7 +9,7 @@ hypertext:
key: ./cert.key
pem: ./cert.pem
limitation:
max_body_size: -1
max_body_size: 536870912
max_qps: -1
ports:
- :8000

View File

@ -9,7 +9,7 @@ hypertext:
key: ./cert.key
pem: ./cert.pem
limitation:
max_body_size: -1
max_body_size: 536870912
max_qps: -1
ports:
- :8000

View File

@ -9,7 +9,7 @@ hypertext:
key: ./cert.key
pem: ./cert.pem
limitation:
max_body_size: -1
max_body_size: 536870912
max_qps: -1
ports:
- :8000