Skip to content

armgit / fider

Public Imported from GitHub
0

Open platform to collect and prioritize feedback

fix: show correct DNS instructions when using apex domain (#378)

Guilherme Oenninge105c3a2cd8f
diff --git a/app/cmd/routes.go b/app/cmd/routes.go
index ecaf8f7e0..1e7bf77ad 100644
--- a/app/cmd/routes.go
+++ b/app/cmd/routes.go
@@ -104,7 +104,7 @@ func routes(r *web.Engine) *web.Engine {
private.Use(middlewares.IsAuthorized(models.RoleCollaborator, models.RoleAdministrator))
- private.Get("/admin", handlers.Page())
+ private.Get("/admin", handlers.GeneralSettingsPage())
private.Get("/admin/privacy", handlers.Page())
private.Get("/admin/invitations", handlers.Page())
private.Get("/admin/members", handlers.ManageMembers())
diff --git a/app/cmd/server.go b/app/cmd/server.go
index 89ca3a795..79456eae1 100644
--- a/app/cmd/server.go
+++ b/app/cmd/server.go
@@ -17,11 +17,11 @@ import (
//RunServer starts the Fider Server
//Returns an exitcode, 0 for OK and 1 for ERROR
func RunServer(settings *models.SystemSettings) int {
-
- e := routes(web.New(settings))
fmt.Printf("Application is starting...\n")
fmt.Printf("GO_ENV: %s\n", env.Current())
+ e := routes(web.New(settings))
+
go e.Start(":" + env.GetEnvOrDefault("PORT", "3000"))
return listenSignals(e, settings)
}
diff --git a/app/handlers/admin.go b/app/handlers/admin.go
index 5f95359f0..ee9c20634 100644
--- a/app/handlers/admin.go
+++ b/app/handlers/admin.go
@@ -2,9 +2,23 @@ package handlers
import (
"github.com/getfider/fider/app/actions"
+ "github.com/getfider/fider/app/pkg/env"
"github.com/getfider/fider/app/pkg/web"
)
+// GeneralSettingsPage is the general settings page
+func GeneralSettingsPage() web.HandlerFunc {
+ return func(c web.Context) error {
+ publicIP, err := env.GetPublicIP()
+ if err != nil {
+ c.Logger().Error(err)
+ }
+ return c.Page(web.Map{
+ "publicIP": publicIP,
+ })
+ }
+}
+
// UpdateSettings update current tenant' settings
func UpdateSettings() web.HandlerFunc {
return func(c web.Context) error {
diff --git a/app/pkg/env/env.go b/app/pkg/env/env.go
index 5eeca9205..1a71e1c19 100644
--- a/app/pkg/env/env.go
+++ b/app/pkg/env/env.go
@@ -2,10 +2,13 @@ package env
import (
"fmt"
+ "net"
"os"
"strings"
"path"
+
+ "github.com/getfider/fider/app/pkg/errors"
)
// GetEnvOrDefault retrieves the value of the environment variable named by the key.
@@ -60,6 +63,26 @@ func MultiTenantDomain() string {
return ""
}
+var publicIP = make(map[string]string, 0)
+
+// GetPublicIP returns the public IP of current hosting server
+func GetPublicIP() (string, error) {
+ if IsSingleHostMode() {
+ return "", nil
+ }
+
+ domain := MultiTenantDomain()[1:]
+ if _, ok := publicIP[domain]; !ok {
+ addr, err := net.LookupIP(domain)
+ if err == nil {
+ publicIP[domain] = addr[0].String()
+ } else {
+ return "", errors.Wrap(err, "failed to lookup IP of %s", domain)
+ }
+ }
+ return publicIP[domain], nil
+}
+
// Current returns current Fider environment
func Current() string {
env := os.Getenv("GO_ENV")
diff --git a/app/pkg/env/env_test.go b/app/pkg/env/env_test.go
index 888a7ff1b..e9c7d67b0 100644
--- a/app/pkg/env/env_test.go
+++ b/app/pkg/env/env_test.go
@@ -66,3 +66,28 @@ func TestMultiTenantDomain(t *testing.T) {
os.Setenv("HOST_MODE", "single")
Expect(env.MultiTenantDomain()).IsEmpty()
}
+
+func TestGetPublicIP(t *testing.T) {
+ RegisterT(t)
+
+ os.Setenv("HOST_MODE", "multi")
+ os.Setenv("AUTH_ENDPOINT", "https://login.dev.fider.io")
+ ip, err := env.GetPublicIP()
+ Expect(err).IsNil()
+ Expect(ip).Equals("127.0.0.1")
+
+ os.Setenv("AUTH_ENDPOINT", "https://login.fider.io")
+ ip, err = env.GetPublicIP()
+ Expect(err).IsNil()
+ Expect(ip).Equals("174.138.111.44")
+
+ os.Setenv("AUTH_ENDPOINT", "invalidinvalidinvalid.io")
+ ip, err = env.GetPublicIP()
+ Expect(err).IsNotNil()
+ Expect(ip).IsEmpty()
+
+ os.Setenv("HOST_MODE", "single")
+ ip, err = env.GetPublicIP()
+ Expect(err).IsNil()
+ Expect(ip).Equals("")
+}
diff --git a/public/pages/Administration/pages/GeneralSettings.page.tsx b/public/pages/Administration/pages/GeneralSettings.page.tsx
index 27a594d3a..cad4b6391 100644
--- a/public/pages/Administration/pages/GeneralSettings.page.tsx
+++ b/public/pages/Administration/pages/GeneralSettings.page.tsx
@@ -9,6 +9,7 @@ interface GeneralSettingsPageProps {
user: CurrentUser;
tenant: Tenant;
system: SystemSettings;
+ publicIP: string;
}
interface GeneralSettingsPageState {
@@ -54,6 +55,18 @@ export class GeneralSettingsPage extends AdminBasePage<GeneralSettingsPageProps,
}
}
+ public dnsInstructions(): JSX.Element {
+ const isApex = this.state.cname.split(".").length === 2;
+ const recordType = isApex ? "A" : "CNAME";
+ const publicIP = this.props.publicIP || "<error>";
+ const targetRecord = isApex ? publicIP : `${this.props.tenant.subdomain}${this.props.system.domain}`;
+ return (
+ <>
+ <strong>{this.state.cname}</strong> {recordType} <strong>{targetRecord}</strong>
+ </>
+ );
+ }
+
public content() {
return (
<div className="ui form">
@@ -127,13 +140,7 @@ export class GeneralSettingsPage extends AdminBasePage<GeneralSettingsPageProps,
{this.state.cname ? (
[
<p key={0}>Enter the following record into your DNS zone records:</p>,
- <p key={1}>
- <strong>{this.state.cname}</strong> CNAME{" "}
- <strong>
- {this.props.tenant.subdomain}
- {this.props.system.domain}
- </strong>
- </p>,
+ <p key={1}>{this.dnsInstructions()}</p>,
<p key={2}>
Please note that it may take up to 72 hours for the change to take effect worldwide due to DNS
propagation.