Skip to content
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 go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ require (
github.com/tdewolff/minify/v2 v2.23.8
github.com/tidwall/gjson v1.18.0
github.com/tidwall/sjson v1.2.5
github.com/torabian/emi v1.0.31
github.com/torabian/emi v1.0.32
github.com/tus/tusd v1.10.0
github.com/urfave/cli v1.22.17
github.com/wk8/go-ordered-map/v2 v2.1.8
Expand Down
6 changes: 2 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -750,10 +750,8 @@ github.com/tidwall/pretty v1.2.1 h1:qjsOFOWWQl+N3RsoF5/ssm1pHmJJwhjlSbZ51I6wMl4=
github.com/tidwall/pretty v1.2.1/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhsoaGGjNU=
github.com/tidwall/sjson v1.2.5 h1:kLy8mja+1c9jlljvWTlSazM7cKDRfJuR/bOJhcY5NcY=
github.com/tidwall/sjson v1.2.5/go.mod h1:Fvgq9kS/6ociJEDnK0Fk1cpYF4FIW6ZF7LAe+6jwd28=
github.com/torabian/emi v1.0.30 h1:rvUrSOR6HgaKJ6m7AW66cDfd3M+0O+T+1cxKivlC0YM=
github.com/torabian/emi v1.0.30/go.mod h1:jexKgoWHBqSBwWL6/pi2vOtDKFsXwud+2E7j8qKw8B4=
github.com/torabian/emi v1.0.31 h1:N6tGyme4y0DYRxKJUY8+Wa14M+s8QWUKWPEahfbRglw=
github.com/torabian/emi v1.0.31/go.mod h1:jexKgoWHBqSBwWL6/pi2vOtDKFsXwud+2E7j8qKw8B4=
github.com/torabian/emi v1.0.32 h1:OPBKhEgjsQtKjDcEVOzqZAaoyuqvGX+ljrCVSBjiMOk=
github.com/torabian/emi v1.0.32/go.mod h1:jexKgoWHBqSBwWL6/pi2vOtDKFsXwud+2E7j8qKw8B4=
github.com/tus/tusd v1.10.0 h1:oQIxjxrSD6mjvYkqIjDlB3KVoEA1DWSzqCgWcTPP/ok=
github.com/tus/tusd v1.10.0/go.mod h1:2k5gtwQX7v1FbeYcCk1O5Sp/sOL9D9iBBtQ7n6XPyBo=
github.com/twitchyliquid64/golang-asm v0.15.1 h1:SU5vSMR7hnwNxj24w34ZyCi/FmDZTkS4MhqMhdFk5YI=
Expand Down
18 changes: 13 additions & 5 deletions modules/fireback/CoreUtils.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"log"
"regexp"
"strconv"
"strings"

"github.com/gin-gonic/gin"
"github.com/manifoldco/promptui"
Expand Down Expand Up @@ -340,6 +341,10 @@ func GetHttpCommand(engineFn func(cfg2 HttpServerInstanceConfig) *gin.Engine) cl
Name: "watch",
Usage: "Monitor server stat using charts and interactive graphics",
},
&cli.StringFlag{
Name: "domains",
Usage: "Mimics the runtime on specific domains locally, for example: test.com,test.pl. If ssl enabled, the certificate needs to include the domains.",
},
&cli.BoolFlag{
Name: "ssl",
Usage: "Runs ssl server on 443 port",
Expand All @@ -365,19 +370,22 @@ func GetHttpCommand(engineFn func(cfg2 HttpServerInstanceConfig) *gin.Engine) cl
},
Name: "start",
Aliases: []string{"s"},
Usage: "Starts http server only",
Usage: "Starts http(s) server only, has few configuration",
Action: func(c *cli.Context) error {

initLogger()
if !config.Production {
Doctor()
}

cfg2 := HttpServerInstanceConfig{
Monitor: c.Bool("watch"),
Port: c.Int64("port"),
SSL: c.Bool("ssl"),
Slow: c.Bool("slow"),
Monitor: c.Bool("watch"),
Port: c.Int64("port"),
SSL: c.Bool("ssl"),
Slow: c.Bool("slow"),
VirtualDomains: strings.Split(c.String("domains"), ","),
}

engine := engineFn(cfg2)
CreateHttpServer(engine, cfg2)

Expand Down
2 changes: 1 addition & 1 deletion modules/fireback/EventBusSubscriptionAction.dyno.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ func EventBusSubscriptionActionReactiveHandler(factory func(
return func(ctx *gin.Context) {
read := make(chan EventBusSubscriptionActionReadChan)
done := make(chan bool)
c, err := Upgrader.Upgrade(ctx.Writer, ctx.Request, nil)
c, err := upgraderEventBusSubscriptionAction.Upgrade(ctx.Writer, ctx.Request, nil)
if err != nil {
c.WriteMessage(websocket.TextMessage, []byte(err.Error()))
c.Close()
Expand Down
2 changes: 1 addition & 1 deletion modules/fireback/ReactiveSearchAction.dyno.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ func ReactiveSearchActionReactiveHandler(factory func(
return func(ctx *gin.Context) {
read := make(chan ReactiveSearchActionReadChan)
done := make(chan bool)
c, err := Upgrader.Upgrade(ctx.Writer, ctx.Request, nil)
c, err := upgraderReactiveSearchAction.Upgrade(ctx.Writer, ctx.Request, nil)
if err != nil {
c.WriteMessage(websocket.TextMessage, []byte(err.Error()))
c.Close()
Expand Down
125 changes: 125 additions & 0 deletions modules/fireback/VirtualDomains.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
package fireback

import (
"os"
"runtime"
"strings"
)

func hostsPath() string {
switch runtime.GOOS {
case "windows":
return `C:\Windows\System32\drivers\etc\hosts`
default:
return "/etc/hosts"
}
}

// This can be even changed per project
const markerStart = "# local-fb-domain-sim-start"
const markerEnd = "# local-fb-domain-sim-end"

func EnableDomain(domain string) error {
path := hostsPath()

data, err := os.ReadFile(path)
if err != nil {
return err
}

content := string(data)

domains := extractDomains(content)
domains[domain] = true

newBlock := buildBlock(domains)

content = removeBlock(content)
content = strings.TrimSpace(content) + "\n\n" + newBlock + "\n"

return os.WriteFile(path, []byte(content), 0644)
}

func DisableDomain(domain string) error {
path := hostsPath()

data, err := os.ReadFile(path)
if err != nil {
return err
}

content := string(data)

domains := extractDomains(content)
delete(domains, domain)

newBlock := buildBlock(domains)

content = removeBlock(content)
content = strings.TrimSpace(content) + "\n\n" + newBlock + "\n"

return os.WriteFile(path, []byte(content), 0644)
}

func extractDomains(content string) map[string]bool {
lines := strings.Split(content, "\n")

inBlock := false
domains := map[string]bool{}

for _, line := range lines {
line = strings.TrimSpace(line)

if line == markerStart {
inBlock = true
continue
}
if line == markerEnd {
inBlock = false
continue
}

if inBlock && line != "" {
parts := strings.Fields(line)
if len(parts) == 2 {
domains[parts[1]] = true
}
}
}

return domains
}

func buildBlock(domains map[string]bool) string {
var sb strings.Builder

sb.WriteString(markerStart + "\n")
for d := range domains {
sb.WriteString("127.0.0.1 " + d + "\n")
}
sb.WriteString(markerEnd)

return sb.String()
}

func removeBlock(content string) string {
lines := strings.Split(content, "\n")
var out []string

skip := false
for _, line := range lines {
if strings.Contains(line, markerStart) {
skip = true
continue
}
if strings.Contains(line, markerEnd) {
skip = false
continue
}
if !skip {
out = append(out, line)
}
}

return strings.Join(out, "\n")
}
2 changes: 2 additions & 0 deletions modules/fireback/fireback-app.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,8 @@ type HttpServerInstanceConfig struct {
SSL bool

Slow bool

VirtualDomains []string
}

func SetupHttpServer(x *FirebackApp, cfg HttpServerInstanceConfig) *gin.Engine {
Expand Down
Loading
Loading