Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: support passing custom bind address on the website #103

Merged
merged 1 commit into from
Apr 1, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions gnoland/website/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package main

import (
"errors"
"flag"
"fmt"
"html/template"
"net/http"
Expand All @@ -21,11 +22,17 @@ import (
"github.com/gnolang/gno/pkgs/sdk/vm" // for error types
)

var flags struct {
bindAddr string
}

func init() {
fmt.Println(vm.Package)
flag.StringVar(&flags.bindAddr, "bind", "127.0.0.1:8888", "server listening address")
}

func main() {
flag.Parse()

app := gotuna.App{
ViewFiles: os.DirFS("./views/"),
Router: gotuna.NewMuxRouter(),
Expand All @@ -43,8 +50,11 @@ func main() {
app.Router.Handle("/static/{path:.+}", handlerStaticFile(app))
// funcs/{rlmname:[a-z][a-z0-9_]*}", handlerGetFunctions(app))

fmt.Println("Running on http://localhost:8888")
http.ListenAndServe("127.0.0.1:8888", app.Router)
fmt.Printf("Running on http://%s\n", flags.bindAddr)
err := http.ListenAndServe(flags.bindAddr, app.Router)
if err != nil {
fmt.Fprintf(os.Stderr, "HTTP server stopped with error: %+v\n", err)
}
}

func handlerHome(app gotuna.App) http.Handler {
Expand Down