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

switch from 0.0.0.0 to 127.0.0.1. Closes #35 #41

Merged
merged 1 commit into from
May 15, 2022
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ Start the development server with `bud run`:

```bash
$ bud run
| Listening on http://0.0.0.0:3000
| Listening on http://127.0.0.1:3000
```

Click on the link to open the browser. You'll be greeted with bud's welcome page.
Expand Down
4 changes: 2 additions & 2 deletions internal/urlx/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (

var ErrParsing = errors.New("urlx: unable to parse")

var defaultHost = "0.0.0.0"
var defaultHost = "127.0.0.1"
var defaultPort = "3000"

func Parse(input string) (*url.URL, error) {
Expand Down Expand Up @@ -61,7 +61,7 @@ func Parse(input string) (*url.URL, error) {
if hasHost && hasPort {
u.Host = parser.url.host + ":" + parser.url.port
} else if hasPort {
u.Host = defaultHost + ":" + parser.url.port // default to 0.0.0.0
u.Host = defaultHost + ":" + parser.url.port // default to 127.0.0.1
} else if hasHost {
u.Host = parser.url.host + ":" + port
} else if !hasPath { // Only append default host:port if there's no path
Expand Down
8 changes: 4 additions & 4 deletions internal/urlx/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ var tests = []struct {
}{
{
input: "5000",
expect: "http://0.0.0.0:5000",
expect: "http://127.0.0.1:5000",
},
{
input: ":5000",
expect: "http://0.0.0.0:5000",
expect: "http://127.0.0.1:5000",
},
{
input: "0",
expect: "http://0.0.0.0:0",
expect: "http://127.0.0.1:0",
},
{
input: "0.0.0.0",
Expand Down Expand Up @@ -67,7 +67,7 @@ var tests = []struct {
},
{
input: "https:",
expect: "https://0.0.0.0:443",
expect: "https://127.0.0.1:443",
},
{
input: "https://localhost:8000/a/b/c",
Expand Down
2 changes: 1 addition & 1 deletion package/socket/socket_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ func TestTCPPassthrough(t *testing.T) {
listener, err := socket.Listen(":0")
is.NoErr(err)
is.Equal(listener.Addr().Network(), "tcp")
is.True(strings.HasPrefix(listener.Addr().String(), "[::]:"))
is.True(strings.HasPrefix(listener.Addr().String(), "127.0.0.1:"))
extras, env, err := socket.Files(listener)
is.NoErr(err)
is.Equal(len(extras), 1)
Expand Down
6 changes: 4 additions & 2 deletions runtime/command/run/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ func (c *Command) startApp(ctx context.Context, hotServer *hot.Server) error {
console.Error(err.Error())
return nil
}
console.Info("Ready on http://0.0.0.0" + c.Port)
// TODO: host should be dynamic
console.Info("Ready on http://127.0.0.1" + c.Port)
return watcher.Stop
}); err != nil {
return err
Expand Down Expand Up @@ -96,7 +97,8 @@ func (c *Command) startApp(ctx context.Context, hotServer *hot.Server) error {
console.Error(err.Error())
return nil
}
console.Info("Ready on http://0.0.0.0" + c.Port)
// TODO: host should be dynamic
console.Info("Ready on http://127.0.0.1" + c.Port)
return nil
// Hot reload the page
default:
Expand Down
3 changes: 2 additions & 1 deletion runtime/controller/response/response.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,8 @@ func wrapHTML(body string) string {
<body>
` + body + `
<script>
const sse = new EventSource("http://0.0.0.0:35729")
// TODO: host should be dynamic
const sse = new EventSource("http://127.0.0.1:35729")
sse.addEventListener("message", () => { location.reload() })
</script>
</body>
Expand Down
2 changes: 1 addition & 1 deletion runtime/view/dom/dom.gotext
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,6 @@ export default mount({
{{- end }}
target: document.getElementById("bud_target"),
{{- if $.Hot }}
hot: new Hot("http://0.0.0.0:35729/?{{$.Query}}", components),
hot: new Hot("http://127.0.0.1:35729/?{{$.Query}}", components),
{{- end }}
})
8 changes: 4 additions & 4 deletions runtime/view/dom/dom_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func TestServeFile(t *testing.T) {
is.True(strings.Contains(string(code), `text("index")`))
is.True(strings.Contains(string(code), `"/bud/view/index.svelte": view_default`))
is.True(strings.Contains(string(code), `page: "/bud/view/index.svelte",`))
is.True(strings.Contains(string(code), `hot: new Hot("http://0.0.0.0:35729/?page=%2Fbud%2Fview%2Findex.svelte", components)`))
is.True(strings.Contains(string(code), `hot: new Hot("http://127.0.0.1:35729/?page=%2Fbud%2Fview%2Findex.svelte", components)`))

// Unwrapped version with node_modules rewritten
code, err = fs.ReadFile(overlay, "bud/view/index.svelte")
Expand All @@ -57,7 +57,7 @@ func TestServeFile(t *testing.T) {
// Unwrapped version doesn't contain wrapping
is.True(!strings.Contains(string(code), `"/bud/view/index.svelte": view_default`))
is.True(!strings.Contains(string(code), `page: "/bud/view/index.svelte",`))
is.True(!strings.Contains(string(code), `hot: new Hot("http://0.0.0.0:35729/?page=%2Fbud%2Fview%2Findex.svelte", components)`))
is.True(!strings.Contains(string(code), `hot: new Hot("http://127.0.0.1:35729/?page=%2Fbud%2Fview%2Findex.svelte", components)`))

// Read the wrapped version of about/index.svelte with node_modules rewritten
code, err = fs.ReadFile(overlay, "bud/view/about/_index.svelte")
Expand All @@ -67,7 +67,7 @@ func TestServeFile(t *testing.T) {
is.True(strings.Contains(string(code), `text("about")`))
is.True(strings.Contains(string(code), `"/bud/view/about/index.svelte": about_default`))
is.True(strings.Contains(string(code), `page: "/bud/view/about/index.svelte",`))
is.True(strings.Contains(string(code), `hot: new Hot("http://0.0.0.0:35729/?page=%2Fbud%2Fview%2Fabout%2Findex.svelte", components)`))
is.True(strings.Contains(string(code), `hot: new Hot("http://127.0.0.1:35729/?page=%2Fbud%2Fview%2Fabout%2Findex.svelte", components)`))

// Unwrapped version with node_modules rewritten
code, err = fs.ReadFile(overlay, "bud/view/about/index.svelte")
Expand All @@ -78,7 +78,7 @@ func TestServeFile(t *testing.T) {
// Unwrapped version doesn't contain wrapping
is.True(!strings.Contains(string(code), `"/bud/view/about/index.svelte": about_default`))
is.True(!strings.Contains(string(code), `page: "/bud/view/about/index.svelte",`))
is.True(!strings.Contains(string(code), `hot: new Hot("http://0.0.0.0:35729/?page=%2Fbud%2Fview%2Fabout%2Findex.svelte", components)`))
is.True(!strings.Contains(string(code), `hot: new Hot("http://127.0.0.1:35729/?page=%2Fbud%2Fview%2Fabout%2Findex.svelte", components)`))
}

func TestNodeModules(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion runtime/web/welcome/build/bud/view/_index.svelte.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.