Skip to content

Commit

Permalink
Add external-ip function by Alex Ellis
Browse files Browse the repository at this point in the history
Original source from:

https://github.com/openfaas/cloud-functions

Signed-off-by: Alex Ellis (OpenFaaS Ltd) <alexellis2@gmail.com>
  • Loading branch information
alexellis committed Oct 24, 2023
1 parent e61f8d1 commit 9b0d8fb
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
31 changes: 31 additions & 0 deletions external-ip/handler.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Copyright (c) 2023 Alex Ellis, OpenFaaS Ltd
// Licensed under the MIT license, see LICENSE.md file.

package function

import (
"io"
"net/http"
)

func Handle(w http.ResponseWriter, r *http.Request) {

if r.Body != nil {
defer r.Body.Close()
}

res, err := http.Get("https://api.ipify.org")
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}

for k, v := range res.Header {
w.Header().Set(k, v[0])
}

if res.Body != nil {
defer res.Body.Close()
io.Copy(w, res.Body)
}
}
5 changes: 5 additions & 0 deletions stack.yml
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,11 @@ functions:
handler: ./certinfo
image: ${SERVER:-ghcr.io}/${OWNER:-openfaas}/certinfo-fn:${TAG:-latest}

external-ip:
lang: golang-middleware
handler: ./external-ip
image: ${SERVER:-ghcr.io}/${OWNER:-openfaas}/external-ip-fn:${TAG:-latest}

configuration:
templates:
- name: golang-middleware
Expand Down

0 comments on commit 9b0d8fb

Please sign in to comment.