Skip to content

Commit 4af29d1

Browse files
authored
Add basic-auth flag to ngrok (ddev#4719)
1 parent d95902c commit 4af29d1

File tree

6 files changed

+17
-4
lines changed

6 files changed

+17
-4
lines changed

.spellcheckwordlist.txt

+1
Original file line numberDiff line numberDiff line change
@@ -438,6 +438,7 @@ nfsd
438438
nfsmount
439439
nginx
440440
ngrok
441+
ngrok's
441442
node
442443
nodejs
443444
noerrors

cmd/ddev/cmd/share.go

+10-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import (
1313
var DdevShareCommand = &cobra.Command{
1414
Use: "share [project]",
1515
Short: "Share project on the internet via ngrok.",
16-
Long: `Use "ddev share" or add on extra ngrok commands, like "ddev share --basic-auth username:pass1234". Although a few ngrok commands are supported directly, any ngrok flag can be added in the ngrok_args section of .ddev/config.yaml. Requires a free or paid account on ngrok.com; use the "ngrok authtoken" command to set up ngrok.`,
16+
Long: `Requires a free or paid account on ngrok.com, use the "ngrok config add-authtoken <token>" command to set up ngrok. Although a few ngrok commands are supported directly, any ngrok flag can be added in the ngrok_args section of .ddev/config.yaml.`,
1717
Example: `ddev share
1818
ddev share --basic-auth username:pass1234
1919
ddev share myproject`,
@@ -45,6 +45,13 @@ ddev share myproject`,
4545
if app.NgrokArgs != "" {
4646
ngrokArgs = append(ngrokArgs, strings.Split(app.NgrokArgs, " ")...)
4747
}
48+
if cmd.Flags().Changed("basic-auth") {
49+
auth, err := cmd.Flags().GetString("basic-auth")
50+
if err != nil {
51+
util.Failed("unable to get --basic-auth flag: %v", err)
52+
}
53+
ngrokArgs = append(ngrokArgs, "--basic-auth="+auth)
54+
}
4855
if cmd.Flags().Changed("subdomain") {
4956
sub, err := cmd.Flags().GetString("subdomain")
5057
if err != nil {
@@ -91,5 +98,6 @@ ddev share myproject`,
9198

9299
func init() {
93100
RootCmd.AddCommand(DdevShareCommand)
94-
DdevShareCommand.Flags().String("subdomain", "", `ngrok --subdomain argument, as in "ngrok --subdomain my-subdomain:, requires paid ngrok.com account"`)
101+
DdevShareCommand.Flags().String("basic-auth", "", `works as in "ngrok http --basic-auth username:pass1234"`)
102+
DdevShareCommand.Flags().String("subdomain", "", `requires a paid ngrok account, works as in "ngrok http --subdomain mysite"`)
95103
}

docs/content/users/configuration/config.md

+3
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,9 @@ Extra flags for [configuring ngrok](https://ngrok.com/docs/ngrok-agent/config) w
281281

282282
Example: `--basic-auth username:pass1234`.
283283

284+
!!!warning
285+
Some ngrok flags, such as `--subdomain`, require a paid ngrok account.
286+
284287
## `no_bind_mounts`
285288

286289
Whether to not use Docker bind mounts.

docs/content/users/topics/sharing.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ There are at least three different ways to share a running DDEV project outside
1616

1717
`ddev share` proxies the project via [ngrok](https://ngrok.com), and it’s by far the easiest way to solve the problem of sharing your project with others on your team or around the world. It’s built into DDEV and “just works” for most people, and requires a free or paid [ngrok.com](https://ngrok.com) account. All you do is run `ddev share` and then give the resultant URL to your collaborator or use it on your mobile device. [Read the basic how-to from DrupalEasy](https://www.drupaleasy.com/blogs/ultimike/2019/06/sharing-your-ddev-local-site-public-url-using-ddev-share-and-ngrok) or run `ddev share -h` for more.
1818

19-
There are CMSes that make this a little harder, especially WordPress and Magento 2. Both of those only respond to a single base URL, and that URL is coded into the database, so it makes this a little harder. For both of these I recommend paying ngrok the $5/month for a [basic plan](https://ngrok.com/pricing) so you can use a stable subdomain with ngrok.
19+
CMSes like WordPress and Magento 2 make this a little harder by only responding to a single base URL that’s coded into the database. ngrok’s $8/month [personal plan](https://ngrok.com/pricing) allows you to use a persistent subdomain so you won’t have to frequently change the base URL.
2020

2121
### Setting up a Stable ngrok Subdomain
2222

docs/content/users/usage/commands.md

+1
Original file line numberDiff line numberDiff line change
@@ -1079,6 +1079,7 @@ ddev service enable solr
10791079

10801080
Flags:
10811081

1082+
* `--basic-auth`: Username and password, separated by a colon.
10821083
* `--subdomain`: Subdomain to use with paid ngrok account.
10831084

10841085
Example:

pkg/ddevapp/templates.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ const ConfigInstructions = `
161161
162162
# ngrok_args: --basic-auth username:pass1234
163163
# Provide extra flags to the "ngrok http" command, see
164-
# https://ngrok.com/docs#http or run "ngrok http -h"
164+
# https://ngrok.com/docs/ngrok-agent/config or run "ngrok http -h"
165165
166166
# disable_settings_management: false
167167
# If true, ddev will not create CMS-specific settings files like

0 commit comments

Comments
 (0)