Skip to content
Open
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
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,10 @@ brew upgrade yusuf-musleh/mmar-tap/mmar

### Docker

The fastest way to create a tunnel what is running on your `localhost:8080` using [Docker](https://www.docker.com/) is by running this command:
The fastest way to create a tunnel what is running on your `https://project.test:443` using [Docker](https://www.docker.com/) is by running this command:

```
docker run --rm --network host ghcr.io/yusuf-musleh/mmar:v0.2.6 client --local-port 8080
docker run --rm --network host ghcr.io/yusuf-musleh/mmar:v0.2.6 client --local-proto https --local-host project.test --local-port 443
```
Comment on lines -68 to 72
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can probably add it as an additional instruction/command rather than replacing this one, as this example is likely more common for users.


### Windows
Expand Down Expand Up @@ -133,6 +133,8 @@ You can define the various mmar command flags in environment variables rather th
MMAR__SERVER_HTTP_PORT -> mmar server --http-port
MMAR__SERVER_TCP_PORT -> mmar server --tcp-port
MMAR__LOCAL_PORT -> mmar client --local-port
MMAR__LOCAL_HOST -> mmar client --local-host
MMAR__LOCAL_PROTO -> mmar client --local-proto
MMAR__TUNNEL_HTTP_PORT -> mmar client --tunnel-http-port
MMAR__TUNNEL_TCP_PORT -> mmar client --tunnel-tcp-port
MMAR__TUNNEL_HOST -> mmar client --tunnel-host
Expand Down
12 changes: 12 additions & 0 deletions cmd/mmar/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,16 @@ func main() {
utils.EnvVarOrDefault(constants.MMAR_ENV_VAR_LOCAL_PORT, constants.CLIENT_LOCAL_PORT),
constants.CLIENT_LOCAL_PORT_HELP,
)
clientLocalHost := clientCmd.String(
"local-host",
utils.EnvVarOrDefault(constants.MMAR_ENV_VAR_LOCAL_HOST, constants.CLIENT_LOCAL_HOST),
constants.CLIENT_LOCAL_HOST_HELP,
)
clientLocalProto := clientCmd.String(
"local-proto",
utils.EnvVarOrDefault(constants.MMAR_ENV_VAR_LOCAL_PROTO, constants.CLIENT_LOCAL_PROTO),
constants.CLIENT_LOCAL_PROTO_HELP,
)
clientTunnelHttpPort := clientCmd.String(
"tunnel-http-port",
utils.EnvVarOrDefault(constants.MMAR_ENV_VAR_TUNNEL_HTTP_PORT, constants.TUNNEL_HTTP_PORT),
Expand Down Expand Up @@ -68,6 +78,8 @@ func main() {
clientCmd.Parse(os.Args[2:])
mmarClientConfig := client.ConfigOptions{
LocalPort: *clientLocalPort,
LocalHost: *clientLocalHost,
LocalProto: *clientLocalProto,
TunnelHttpPort: *clientTunnelHttpPort,
TunnelTcpPort: *clientTunnelTcpPort,
TunnelHost: *clientTunnelHost,
Expand Down
30 changes: 18 additions & 12 deletions constants/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,22 @@ package constants
const (
MMAR_VERSION = "0.2.6"

VERSION_CMD = "version"
SERVER_CMD = "server"
CLIENT_CMD = "client"
CLIENT_LOCAL_PORT = "8000"
SERVER_HTTP_PORT = "3376"
SERVER_TCP_PORT = "6673"
TUNNEL_HOST = "mmar.dev"
TUNNEL_HTTP_PORT = "443"
VERSION_CMD = "version"
SERVER_CMD = "server"
CLIENT_CMD = "client"
CLIENT_LOCAL_PORT = "8000"
CLIENT_LOCAL_HOST = "localhost"
CLIENT_LOCAL_PROTO = "http"
SERVER_HTTP_PORT = "3376"
SERVER_TCP_PORT = "6673"
TUNNEL_HOST = "mmar.dev"
TUNNEL_HTTP_PORT = "443"

MMAR_ENV_VAR_SERVER_HTTP_PORT = "MMAR__SERVER_HTTP_PORT"
MMAR_ENV_VAR_SERVER_TCP_PORT = "MMAR__SERVER_TCP_PORT"
MMAR_ENV_VAR_LOCAL_PORT = "MMAR__LOCAL_PORT"
MMAR_ENV_VAR_LOCAL_HOST = "MMAR__LOCAL_HOST"
MMAR_ENV_VAR_LOCAL_PROTO = "MMAR__LOCAL_PROTO"
MMAR_ENV_VAR_TUNNEL_HTTP_PORT = "MMAR__TUNNEL_HTTP_PORT"
MMAR_ENV_VAR_TUNNEL_TCP_PORT = "MMAR__TUNNEL_TCP_PORT"
MMAR_ENV_VAR_TUNNEL_HOST = "MMAR__TUNNEL_HOST"
Expand All @@ -25,10 +29,12 @@ const (
SERVER_HTTP_PORT_HELP = "Define port where mmar will bind to and run on server for HTTP requests."
SERVER_TCP_PORT_HELP = "Define port where mmar will bind to and run on server for TCP connections."

CLIENT_LOCAL_PORT_HELP = "Define the port where your local dev server is running to expose through mmar."
CLIENT_HTTP_PORT_HELP = "Define port of mmar HTTP server to make requests through the tunnel."
CLIENT_TCP_PORT_HELP = "Define port of mmar TCP server for client to connect to, creating a tunnel."
TUNNEL_HOST_HELP = "Define host domain of mmar server for client to connect to."
CLIENT_LOCAL_PORT_HELP = "Define the port where your local dev server is running to expose through mmar."
CLIENT_LOCAL_HOST_HELP = "Define the hostname where your local dev server is running to expose through mmar."
CLIENT_LOCAL_PROTO_HELP = "Define the protocol where your local dev server is running to expose (http / https)."
CLIENT_HTTP_PORT_HELP = "Define port of mmar HTTP server to make requests through the tunnel."
CLIENT_TCP_PORT_HELP = "Define port of mmar TCP server for client to connect to, creating a tunnel."
TUNNEL_HOST_HELP = "Define host domain of mmar server for client to connect to."

TUNNEL_MESSAGE_PROTOCOL_VERSION = 3
TUNNEL_MESSAGE_DATA_DELIMITER = '\n'
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
module github.com/yusuf-musleh/mmar

go 1.23.0

7 changes: 5 additions & 2 deletions internal/client/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import (

type ConfigOptions struct {
LocalPort string
LocalHost string
LocalProto string
TunnelHttpPort string
TunnelTcpPort string
TunnelHost string
Expand All @@ -36,14 +38,15 @@ type MmarClient struct {
}

func (mc *MmarClient) localizeRequest(request *http.Request) {
localhost := fmt.Sprintf("http://localhost:%v%v", mc.LocalPort, request.RequestURI)
localhost := fmt.Sprintf("%v://%v:%v%v", mc.LocalProto, mc.LocalHost, mc.LocalPort, request.RequestURI)
localURL, urlErr := url.Parse(localhost)
if urlErr != nil {
log.Fatalf("Failed to parse URL: %v", urlErr)
}

// Set URL to send request to local server
request.URL = localURL
request.Host = mc.LocalHost
// Clear requestURI since it is now a client request
request.RequestURI = ""
}
Expand Down Expand Up @@ -195,7 +198,7 @@ func (mc *MmarClient) ProcessTunnelMessages(ctx context.Context) {
} else {
mc.subdomain = tunnelSubdomain
}
logger.LogTunnelCreated(tunnelSubdomain, mc.TunnelHost, mc.TunnelHttpPort, mc.LocalPort)
logger.LogTunnelCreated(tunnelSubdomain, mc.TunnelHost, mc.TunnelHttpPort, mc.LocalProto, mc.LocalHost, mc.LocalPort)
case protocol.CLIENT_TUNNEL_LIMIT:
limit := logger.ColorLogStr(
constants.RED,
Expand Down
6 changes: 4 additions & 2 deletions internal/logger/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,12 +163,12 @@ func LogStartMmarClient(tunnelHost string, tunnelTcpPort string, tunnelHttpPort
)
}

func LogTunnelCreated(subdomain string, tunnelHost string, tunnelHttpPort string, localPort string) {
func LogTunnelCreated(subdomain string, tunnelHost string, tunnelHttpPort string, localProto string, localHost string, localPort string) {
logStr := `%s

A mmar tunnel is now open on:

>>> %s://%s.%s%s %s http://localhost:%s
>>> %s://%s.%s%s %s %s://%s:%s

`
httpProtocol := "https"
Expand All @@ -192,6 +192,8 @@ A mmar tunnel is now open on:
tunnelHost,
tunnelHttpPortStr,
ColorLogStr(constants.GREEN, "->"),
localProto,
localHost,
localPort,
)
}