mirror of
https://github.com/openfaas/faas.git
synced 2025-06-14 19:26:48 +00:00
Merge branch 'master' of https://github.com/alexellis/faas
This commit is contained in:
commit
22b3e73b96
@ -37,11 +37,14 @@ This binary fwatchdog acts as a watchdog for your function. Features:
|
||||
## 2. Future items
|
||||
|
||||
* Asynchronous / long-running tasks
|
||||
* Built-in TLS termination or guide for termination through NGinx etc
|
||||
* Deeper tests coverage and integration tests
|
||||
* Function store - list of useful predefined functions
|
||||
* Guide for termination through NGinx or built-in TLS termination
|
||||
* Guide for basic authentication over HTTPs (set up externally through NGinx etc)
|
||||
* Documentation about Alexa sample function
|
||||
* Supporting request parameters
|
||||
|
||||
* Deeper tests coverage and integration tests
|
||||
|
||||
## 3. Development and Contributing
|
||||
|
||||
If you would like to consume the project with your own functions then you can use the public images and the supplied `docker stack` file as a template (docker-compose.yml)
|
||||
|
@ -8,6 +8,7 @@ import (
|
||||
"os"
|
||||
"os/exec"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
)
|
||||
|
||||
@ -20,42 +21,61 @@ func (OsEnv) Getenv(key string) string {
|
||||
return os.Getenv(key)
|
||||
}
|
||||
|
||||
func pipeRequest(config *WatchdogConfig, w http.ResponseWriter, r *http.Request) {
|
||||
parts := strings.Split(config.faasProcess, " ")
|
||||
|
||||
targetCmd := exec.Command(parts[0], parts[1:]...)
|
||||
writer, _ := targetCmd.StdinPipe()
|
||||
|
||||
var out []byte
|
||||
var err error
|
||||
var res []byte
|
||||
|
||||
var wg sync.WaitGroup
|
||||
wg.Add(2)
|
||||
|
||||
res, _ = ioutil.ReadAll(r.Body)
|
||||
defer r.Body.Close()
|
||||
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
writer.Write(res)
|
||||
writer.Close()
|
||||
}()
|
||||
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
out, err = targetCmd.CombinedOutput()
|
||||
}()
|
||||
|
||||
wg.Wait()
|
||||
|
||||
if err != nil {
|
||||
if config.writeDebug == true {
|
||||
log.Println(targetCmd, err)
|
||||
}
|
||||
|
||||
w.WriteHeader(500)
|
||||
response := bytes.NewBufferString(err.Error())
|
||||
w.Write(response.Bytes())
|
||||
return
|
||||
}
|
||||
if config.writeDebug == true {
|
||||
os.Stdout.Write(out)
|
||||
}
|
||||
|
||||
// Match header for strict services
|
||||
if r.Header.Get("Content-Type") == "application/json" {
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
}
|
||||
w.WriteHeader(200)
|
||||
w.Write(out)
|
||||
}
|
||||
|
||||
func makeRequestHandler(config *WatchdogConfig) func(http.ResponseWriter, *http.Request) {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
if r.Method == "POST" {
|
||||
parts := strings.Split(config.faasProcess, " ")
|
||||
|
||||
targetCmd := exec.Command(parts[0], parts[1:]...)
|
||||
writer, _ := targetCmd.StdinPipe()
|
||||
|
||||
res, _ := ioutil.ReadAll(r.Body)
|
||||
defer r.Body.Close()
|
||||
|
||||
writer.Write(res)
|
||||
writer.Close()
|
||||
|
||||
out, err := targetCmd.CombinedOutput()
|
||||
|
||||
if err != nil {
|
||||
if config.writeDebug == true {
|
||||
log.Println(targetCmd, err)
|
||||
}
|
||||
|
||||
w.WriteHeader(500)
|
||||
response := bytes.NewBufferString(err.Error())
|
||||
w.Write(response.Bytes())
|
||||
return
|
||||
}
|
||||
if config.writeDebug == true {
|
||||
os.Stdout.Write(out)
|
||||
}
|
||||
|
||||
// Match header for strict services
|
||||
if r.Header.Get("Content-Type") == "application/json" {
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
}
|
||||
w.WriteHeader(200)
|
||||
w.Write(out)
|
||||
pipeRequest(config, w, r)
|
||||
} else {
|
||||
w.WriteHeader(http.StatusMethodNotAllowed)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user