Skip to content
This repository has been archived by the owner on Feb 24, 2024. It is now read-only.

INFO log does not display correct port when starting buffalo dev #2151

Closed
iateadonut opened this issue Oct 23, 2021 · 4 comments
Closed

INFO log does not display correct port when starting buffalo dev #2151

iateadonut opened this issue Oct 23, 2021 · 4 comments

Comments

@iateadonut
Copy link

Description

If you set the port, the command buffalo dev does not display the correct port.

Steps to Reproduce the Problem

Use this to change the port number:

	app := actions.App()
	srv := servers.New()
	srv.Addr = "127.0.0.1:8001"
	if err := app.Serve(srv); err != nil {
		log.Fatal(err)
	}

Expected Behavior

on buffalo dev, the startup log should read:

INFO[2021-10-23T14:10:32+09:00] Starting application at 127.0.0.1:8001

Actual Behavior

on buffalo dev, the startup log actually read:

INFO[2021-10-23T14:10:32+09:00] Starting application at 127.0.0.1:3000

Info

Please run buffalo info and paste the information below where it says "PASTE_HERE".

-> Go: Checking installation
✓ The `go` executable was found on your system at: /usr/local/go/bin/go

-> Go: Checking minimum version requirements
✓ Your version of Go, 1.17, meets the minimum requirements.

-> Go: Checking Package Management
✓ You are using Go Modules (`go`) for package management.

-> Go: Checking PATH
✓ Your PATH contains /home/dan/go/bin.

-> Node: Checking installation
✓ The `node` executable was found on your system at: /usr/local/bin/node

-> Node: Checking minimum version requirements
✓ Your version of Node, v14.16.1, meets the minimum requirements.

-> NPM: Checking installation
✓ The `npm` executable was found on your system at: /usr/local/bin/npm

-> NPM: Checking minimum version requirements
✓ Your version of NPM, 7.23.0, meets the minimum requirements.

-> Yarn: Checking installation
✓ The `yarnpkg` executable was found on your system at: /usr/local/bin/yarnpkg

-> Yarn: Checking minimum version requirements
✓ Your version of Yarn, 1.22.11, meets the minimum requirements.

-> PostgreSQL: Checking installation
✘ The `postgres` executable could not be found on your system.
For help setting up your Postgres environment please follow the instructions for you platform at:

https://www.postgresql.org/download/

-> MySQL: Checking installation
✓ The `mysql` executable was found on your system at: /usr/bin/mysql

-> MySQL: Checking minimum version requirements
✓ Your version of MySQL, 8.0.21, meets the minimum requirements.

-> SQLite3: Checking installation
✘ The `sqlite3` executable could not be found on your system.
For help setting up your SQLite3 environment please follow the instructions for you platform at:

https://www.sqlite.org/download.html

-> Cockroach: Checking installation
✘ The `cockroach` executable could not be found on your system.
For help setting up your Cockroach environment please follow the instructions for you platform at:

https://www.cockroachlabs.com/docs/stable/

-> Buffalo (CLI): Checking installation
✓ The `buffalo` executable was found on your system at: /home/dan/bin/buffalo

-> Buffalo (CLI): Checking minimum version requirements
✓ Your version of Buffalo (CLI), v0.17.2, meets the minimum requirements.

-> Buffalo: Application Details
Pwd         /home/dan/go/src/co2capturecoin/co2c_com
Root        /home/dan/go/src/co2capturecoin/co2c_com
GoPath      /home/dan/go
PackagePkg  co2capturecoin/co2c_com
ActionsPkg  co2capturecoin/co2c_com/actions
ModelsPkg   co2capturecoin/co2c_com/models
GriftsPkg   co2capturecoin/co2c_com/grifts
WithModules true
Name        co2c_com
Bin         bin/co2c_com
VCS         git
WithPop     true
WithSQLite  false
WithDep     false
WithWebpack true
WithNodeJs  true
WithYarn    true
WithDocker  true
WithGrifts  true
AsWeb       true
AsAPI       false
InApp       true
PackageJSON {map[build:webpack -p --progress dev:webpack --watch]}

-> Buffalo: config/buffalo-app.toml
name = "co2c_com"
bin = "bin/co2c_com"
vcs = "git"
with_pop = true
with_sqlite = false
with_dep = false
with_webpack = true
with_nodejs = true
with_yarn = true
with_docker = true
with_grifts = true
as_web = true
as_api = false

-> Buffalo: config/buffalo-plugins.toml
[[plugin]]
  binary = "buffalo-pop"
  go_get = "github.com/gobuffalo/buffalo-pop/v2"

-> Buffalo: go.mod
module co2capturecoin/co2c_com

go 1.16

require (
	github.com/gobuffalo/buffalo v0.17.3
	github.com/gobuffalo/buffalo-pop/v2 v2.3.0
	github.com/gobuffalo/envy v1.9.0
	github.com/gobuffalo/mw-csrf v1.0.0
	github.com/gobuffalo/mw-forcessl v0.0.0-20200131175327-94b2bd771862
	github.com/gobuffalo/mw-i18n v1.1.0
	github.com/gobuffalo/mw-paramlogger v1.0.0
	github.com/gobuffalo/packr/v2 v2.8.1
	github.com/gobuffalo/pop/v5 v5.3.4
	github.com/gobuffalo/suite v2.8.2+incompatible
	github.com/markbates/grift v1.5.0
	github.com/smartcar/go-sdk v1.4.0
	github.com/unrolled/secure v1.0.9
)

@sio4
Copy link
Member

sio4 commented Oct 23, 2021

Yeah, Indeed. the output is not correct. I think we need to fix it to match the reality.

However, from my quick investigation, I found that it uses an interface for the server (servers.Server). In my opinion, assigning the variable Addr directly from the user's code could not be matched with the concept behind the server implementation.

Is there any reason you used servers.New() and hardcoded the Addr in your app code instead of using the environment variable PORT? For example:

$ PORT=8001 buffalo dev
<...>
Starting application at http://127.0.0.1:8001

@sio4
Copy link
Member

sio4 commented Oct 23, 2021

This patch could be a quick fix for the issue if we really need to allow the manual assigning of the address. Or, keep the current behavior as is, and documenting the behavior could be another solution for this.

--- buffalo/server.go	2021-10-19 22:50:58.659821065 +0900
+++ [email protected]/server.go	2021-10-23 18:22:37.082807523 +0900
@@ -19,7 +19,7 @@
 // interrupt and kill signals and will attempt to stop the application
 // gracefully. This will also start the Worker process, unless WorkerOff is enabled.
 func (a *App) Serve(srvs ...servers.Server) error {
-	a.Logger.Infof("Starting application at http://%s", a.Options.Addr)
+	a.Logger.Infof("Starting application")
 
 	payload := events.Payload{
 		"app": a,
@@ -84,6 +84,7 @@
 	}
 
 	for _, s := range srvs {
+		a.Logger.Infof("Starting application server at %v", s.GetAddr())
 		s.SetAddr(a.Addr)
 		go func(s servers.Server) {
 			if err := s.Start(ctx, a); err != nil {
--- buffalo/servers/listener.go	2021-10-19 22:50:58.659821065 +0900
+++ [email protected]/servers/listener.go	2021-10-23 17:29:48.173865901 +0900
@@ -19,6 +19,10 @@
 	}
 }
 
+func (s *Listener) GetAddr() string {
+	return s.Server.Addr
+}
+
 // Start the server
 func (s *Listener) Start(c context.Context, h http.Handler) error {
 	s.Handler = h
--- buffalo/servers/servers.go	2021-10-19 22:50:58.659821065 +0900
+++ [email protected]/servers/servers.go	2021-10-23 17:27:11.996470557 +0900
@@ -11,6 +11,7 @@
 	Shutdown(context.Context) error
 	Start(context.Context, http.Handler) error
 	SetAddr(string)
+	GetAddr() string
 }
 
 // Wrap converts a standard *http.Server to a buffalo.Server
--- buffalo/servers/simple.go	2021-10-19 22:50:58.659821065 +0900
+++ [email protected]/servers/simple.go	2021-10-23 18:19:44.243387725 +0900
@@ -17,6 +17,10 @@
 	}
 }
 
+func (s *Simple) GetAddr() string {
+	return s.Server.Addr
+}
+
 // Start the server
 func (s *Simple) Start(c context.Context, h http.Handler) error {
 	s.Handler = h
--- buffalo/servers/tls.go	2021-10-19 22:50:58.659821065 +0900
+++ [email protected]/servers/tls.go	2021-10-23 18:20:03.283762539 +0900
@@ -19,6 +19,10 @@
 	}
 }
 
+func (s *TLS) GetAddr() string {
+	return s.Server.Addr
+}
+
 // Start the server
 func (s *TLS) Start(c context.Context, h http.Handler) error {
 	s.Handler = h

@iateadonut
Copy link
Author

You're right. What I suggest is unnecessary.

@sio4
Copy link
Member

sio4 commented Nov 3, 2021

I didn't intend to say your suggestion is unnecessary since indeed the information on the log is not correct. I would like to keep watching this issue and fix the issue until the wrong log to be fixed. :-)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants