mirror of
https://github.com/openfaas/faas.git
synced 2025-06-11 01:36:47 +00:00
Combine stdout/stderr (experimental)
Don't panic on error, keep alive and return 500.
This commit is contained in:
parent
33a8f012f5
commit
b11c400436
@ -1,6 +1,7 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
@ -20,18 +21,31 @@ func main() {
|
|||||||
|
|
||||||
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
|
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
|
||||||
if r.Method == "POST" {
|
if r.Method == "POST" {
|
||||||
|
|
||||||
process := os.Getenv("fprocess")
|
process := os.Getenv("fprocess")
|
||||||
|
|
||||||
parts := strings.Split(process, " ")
|
parts := strings.Split(process, " ")
|
||||||
|
|
||||||
targetCmd := exec.Command(parts[0], parts[1:]...)
|
targetCmd := exec.Command(parts[0], parts[1:]...)
|
||||||
writer, _ := targetCmd.StdinPipe()
|
writer, _ := targetCmd.StdinPipe()
|
||||||
|
|
||||||
res, _ := ioutil.ReadAll(r.Body)
|
res, _ := ioutil.ReadAll(r.Body)
|
||||||
|
|
||||||
writer.Write(res)
|
writer.Write(res)
|
||||||
writer.Close()
|
writer.Close()
|
||||||
out, err := targetCmd.Output()
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
|
out, err := targetCmd.Output()
|
||||||
|
targetCmd.CombinedOutput()
|
||||||
|
if err != nil {
|
||||||
|
log.Println(targetCmd, err)
|
||||||
|
w.WriteHeader(500)
|
||||||
|
response := bytes.NewBufferString(err.Error())
|
||||||
|
w.Write(response.Bytes())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
w.WriteHeader(200)
|
||||||
|
|
||||||
|
// TODO: consider stdout to container as configurable via env-variable.
|
||||||
os.Stdout.Write(out)
|
os.Stdout.Write(out)
|
||||||
w.Write(out)
|
w.Write(out)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user