-
Notifications
You must be signed in to change notification settings - Fork 405
/
Copy pathmain.go
55 lines (44 loc) · 1.16 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package main
import (
"errors"
"fmt"
"net/http"
"os"
ory "github.com/ory/client-go"
)
type App struct {
ory *ory.APIClient
tunnelUrl string
}
func main() {
tunnelPort := os.Getenv("TUNNEL_PORT")
if tunnelPort == "" {
tunnelPort = "4000"
}
// Configure Ory client to use tunnel
c := ory.NewConfiguration()
c.Servers = ory.ServerConfigurations{{URL: fmt.Sprintf("http://localhost:%s", tunnelPort)}}
// Store the tunnel URL for redirects
tunnelUrl := fmt.Sprintf("http://localhost:%s", tunnelPort)
app := &App{
ory: ory.NewAPIClient(c),
tunnelUrl: tunnelUrl,
}
mux := http.NewServeMux()
// dashboard
mux.Handle("/", app.sessionMiddleware(app.dashboardHandler))
port := os.Getenv("PORT")
if port == "" {
port = "3000"
}
fmt.Printf("Application launched and running on http://127.0.0.1:%s\n", port)
fmt.Printf("Make sure to run Ory Tunnel in another terminal:\n")
fmt.Printf("npx @ory/cli tunnel --dev http://localhost:%s\n", port)
// start the server
err := http.ListenAndServe(":"+port, mux)
if errors.Is(err, http.ErrServerClosed) {
fmt.Println("Server closed")
return
}
fmt.Printf("Could not start server: %s\n", err)
}