Question: I have a service that has an internal list of directive names (lets call it `listService`). In the spirit of loosely coupled applications I want other modules to be able to add their own directives to that list instead of statically defining it in the service module.

I understand that I can create a provider in order to configure a service like this:

```
app.provider("listService", ServiceProvider);

app.config(["listServiceProvider", function(listServiceProvider) {
    listServiceProvider.add("myDirective");
}]);

```

At the same time, I don't want all the modules that define directives to depend on the service. So what I would like to do is "if this service is used in this project: configure it; else: ignore".

Unfortunately, the above code produces a [module error](https://docs.angularjs.org/error/$injector/modulerr) if `listServiceProvider` is not available. I also tried to use a [decorator](https://docs.angularjs.org/api/auto/service/$provide#decorator) with the same result.

So how can I *optionally* configure a service in order to have a loosely coupled application?

Answer: 
So given for example

```
x = 'https://1.amodule.myapp.appspot.com'

```

you need to replace **all but the last two** dots with `-dot-` (the last two must remain since the `.appspot.com` part much stay untouched).

Given this, I'd recommend:

```
>>> x = 'https://1.amodule.myapp.appspot.com'
>>> dots = x.count('.')
>>> x.replace('.', '-dot-', dots - 2)
'https://1-dot-amodule-dot-myapp.appspot.com'

```

The key ideas: `x.count('.')` tells you how many dots in all string `x` contains; the third optional argument to `x.replace` tells Python **how many** dots, at most, are to be replaced.
The `gcloud` command-line utility now has [`gcloud app browse`](https://cloud.google.com/sdk/gcloud/reference/app/browse), which will take you to the correct URL. For example, the following commands will launch the URL `https://1-dot-amodule-dot-myapp.appspot.com`:

```
gcloud config set project myapp
gcloud app browse --service="amodule" --version="1"

```

Or

```
gcloud app browse --project="myapp" --service="amodule" --version="1"

```

By default it will attempt opening the URL in a browser, but you can use the `--no-launch-browser` flag to only display the URL.

Full docs at <https://cloud.google.com/sdk/gcloud/reference/app/browse>.