## Enable CODE for development

For editing a document, there must be a way to communicate between the collabora server and the symfony server, in
both directions. The domain name should also be the same for collabora server and for the browser which access to the
online editor.

### Using ngrok (or other http tunnel)

One can configure a tunnel server to expose your local installation to the web and access to your local server using the
tunnel url.

##### Start ngrok

This can be achieved using [ngrok ](https://ngrok.com/).

   The configuration of ngrok is outside the scope of this document. Refers to the ngrok's documentation.

   # ensuring that your server is running through http and port 8000
   ngrok http 8000
   # then open the link given by the ngrok utility, and you should reach your app

At this step, ensure that you can reach your local app using the ngrok url.

##### Configure Collabora

The collabora server must be executed online and configured to access to your ngrok installation. Ensure that the aliasgroup
exists for your ngrok application ([See the CODE documentation: ](https://sdk.collaboraonline.com/docs/installation/Configuration.html#multihost-configuration)).

##### Configure your app

Set the `EDITOR_SERVER` variable to point to your collabora server, this should be done in your `.env.local` file.

At this point, everything must be fine. In case of errors, watch the log from your collabora server, use the [profiler](https://symfony.com/doc/current/profiler.html)
to debug the requests.

   In case of error while validating proof (you'll see those messages in the collabora's logs), you can temporarily disable
   the proof validation adding this code snippet in `config/services.yaml`:

```yaml
      when@dev:
          # add only in the dev environment to avoid security problems
          services:
              ChampsLibres\WopiLib\Contract\Service\ProofValidatorInterface:
                  # this class will always validate proof
                  alias: Chill\WopiBundle\Service\Wopi\NullProofValidator
```

### With a local CODE image

   This configuration is not sure and must be refined. The documentation does not seem entirely valid.

##### Use a local domain name and https for your app

Use the proxy feature from the embedded symfony server to run your app. `See the dedicated doc <https://symfony.com/doc/current/setup/symfony_server.html#local-domain-names>[

Configure also the `https certificate ](https://symfony.com/doc/current/setup/symfony_server.html#enabling-tls)

In this example, your local domain name will be `my-domain` and the url will be `https://my-domain.wip`.

Ensure that the proxy is running.

##### Create a certificate database for collabora

Collabora must validate your certificate generated by the symfony console. For that, you need [to create a NSS database](https://sdk.collaboraonline.com/docs/installation/Configuration.html#validating-digital-signatures)
and configure collabora to use it.

At first, export the certificate for symfony development. Use the graphical interface from your browser to get the
certificate as a PEM file.

```bash
   # create your database in a custom directory
   `mkdir /path/to/your/directory`
   `certutil -N -d /path/to/your/directory`
   `cat /path/to/your/ca.crt | certutil -d . -A symfony -t -t C,P,C,u,w -a`
```

Launch CODE properly configured

```yaml
     collabora:
         image: collabora/code:latest
         environment:
             - SLEEPFORDEBUGGER=0
             - DONT_GEN_SSL_CERT="True"
             # add a path to the database
             - extra_params=--o:ssl.enable=false --o:ssl.termination=false --o:logging.level=7 -o:certificates.database_path=/etc/custom-certificates/nss-database
             - username=admin
             - password=admin
             - dictionaries=en_US
             - aliasgroup1=https://my-domain.wip
         ports:
             - "127.0.0.1:9980:9980"
         volumes:
             - "/path/to/your/directory/nss-database:/etc/custom-certificates/nss-database"
         extra_hosts:
             - "my-domain.wip:host-gateway"
```

##### Configure your app

In your `.env.local` file:

   `EDITOR_SERVER=http://${COLLABORA_HOST}:${COLLABORA_PORT}`

At this step, you should be able to edit a document through collabora.
