Skip to content

Commit

Permalink
add outbound http to same app tinygo example
Browse files Browse the repository at this point in the history
Signed-off-by: Michelle Dhanani <michelle@fermyon.com>
  • Loading branch information
michelleN committed Aug 31, 2023
1 parent 24f098a commit 919c1cc
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module outbound-http-to-same-app

go 1.17

require github.com/fermyon/spin/sdk/go v0.0.0

require github.com/julienschmidt/httprouter v1.3.0 // indirect

replace github.com/fermyon/spin/sdk/go v0.0.0 => ../../../sdk/go/
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package main

import (
"fmt"
"net/http"

spinhttp "github.com/fermyon/spin/sdk/go/http"
)

func init() {
spinhttp.Handle(func(w http.ResponseWriter, r *http.Request) {
resp, err := spinhttp.Get("/hello")
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}

fmt.Fprintln(w, resp.Body)
fmt.Fprintln(w, resp.Header.Get("content-type"))
})
}

func main() {}
18 changes: 16 additions & 2 deletions examples/http-tinygo-outbound-http/spin.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,23 @@ version = "1.0.0"

[[component]]
id = "tinygo-hello"
source = "main.wasm"
allowed_http_hosts = ["https://random-data-api.fermyon.app", "https://postman-echo.com"]
source = "tinygo-hello/main.wasm"
allowed_http_hosts = [
"https://random-data-api.fermyon.app",
"https://postman-echo.com",
]
[component.trigger]
route = "/hello"
[component.build]
workdir = "tinygo-hello"
command = "tinygo build -target=wasi -gc=leaking -no-debug -o main.wasm main.go"

[[component]]
id = "outbound-http-to-same-app"
source = "outbound-http-to-same-app/main.wasm"
allowed_http_hosts = ["self"]
[component.trigger]
route = "/outbound-http-to-same-app"
[component.build]
workdir = "outbound-http-to-same-app"
command = "tinygo build -target=wasi -gc=leaking -no-debug -o main.wasm main.go"
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ require github.com/fermyon/spin/sdk/go v0.0.0

require github.com/julienschmidt/httprouter v1.3.0 // indirect

replace github.com/fermyon/spin/sdk/go v0.0.0 => ../../sdk/go/
replace github.com/fermyon/spin/sdk/go v0.0.0 => ../../../sdk/go/
2 changes: 2 additions & 0 deletions examples/http-tinygo-outbound-http/tinygo-hello/go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
github.com/julienschmidt/httprouter v1.3.0 h1:U0609e9tgbseu3rBINet9P48AI/D3oJs4dN7jwJOQ1U=
github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8IZAc4RVcycCCAKdM=
File renamed without changes.

0 comments on commit 919c1cc

Please sign in to comment.