<commit_before># [Cozy](https://cozy.io) Proxy

Cozy Proxy redirects requests properly to the right application of the Cozy
platform depending on given path. It also handles authentication to the Cozy
for users and devices.

## Install

We assume here that the Cozy platform is correctly [installed](https://raw.github.com/cozy/cozy-setup/gh-pages/assets/images/happycloud.png)
 on your server.

Type this command to install the proxy module:

```sh
$ cozy-monitor install proxy
```

## Contribution

You can contribute to the Cozy Proxy in many ways:

* Pick up an [issue](https://github.com/cozy/cozy-proxy/issues?state=open) and solve it.
* Translate it in [a new language](https://github.com/cozy/cozy-proxy/tree/master/client/app/locales).
* Improve the session management.

## Listen on https

It is recommended to run Cozy Proxy behind a reverse proxy like nginx. The
reverse proxy does the SSL/TLS stuff in that case. But if you want to run Cozy
Proxy with no reverse proxy (low memory server for example), you can set the
following env variables:

```sh
USE_SSL=true
SSL_CRT_PATH=/path/to/server.crt  # /etc/cozy/server.crt by default
SSL_KEY_PATH=/path/to/server.key  # /etc/cozy/server.key by default
```

To use this when the whole Cozy stack is running, you can add this variables
into the Controller configuration file, `/etc/cozy/controller.json`, as
[explained into the
documentation](https://docs.cozy.io/en/hack/cookbooks/controller.html#configuration).
Just add the following lines into this file:

```json
"env": {
  "proxy": {
    "PORT": 443,
    "USE_SSL": true,
    "SSL_CRT_PATH": "/path/to/server.crt",
    "SSL_KEY_PATH": "/path/to/server.key"
  }
}
```

## Hack

To be hacked, the Cozy Proxy dev environment requires that a CouchDB instance
and a Cozy Data System instance are running. Then you can start the Cozy Proxy
this way:

```sh
$ git clone https://github.com/cozy/cozy-proxy.git
$ cd cozy-proxy
$ npm install
$ npm run watch
```

### To hack cozy-proxy using the cozy vagrant

- Forward cozy-home application port from the virtual machine: `config.vm.network :forwarded_port, guest: 9103, host: 9103` in file Vagrantfile
- Go to your cozy-proxy folder `cd your-cozy-proxy-folder`
- Run `npm install`
- Launch cozy-proxy `PORT=9555 HOST="0.0.0.0" npm run watch` (You may use another port)
- You can now access the hacked proxy on `http://localhost:9555` with your navigator

## Tests

![Build Status](https://travis-ci.org/cozy/cozy-proxy.png?branch=master)

To run tests, type the following command into the Cozy Proxy folder:
<commit_msg>Improve documentation (running part)<commit_after># [Cozy](https://cozy.io) Proxy

Cozy Proxy redirects requests properly to the right application of the Cozy
platform depending on given path. It also handles authentication to the Cozy
for users and devices.

## Install

We assume here that the Cozy platform is correctly [installed](https://raw.github.com/cozy/cozy-setup/gh-pages/assets/images/happycloud.png)
 on your server.

Type this command to install the proxy module:

```sh
$ cozy-monitor install proxy
```

## Contribution

You can contribute to the Cozy Proxy in many ways:

* Pick up an [issue](https://github.com/cozy/cozy-proxy/issues?state=open) and solve it.
* Translate it in [a new language](https://github.com/cozy/cozy-proxy/tree/master/client/app/locales).
* Improve the session management.

## Listen on https

It is recommended to run Cozy Proxy behind a reverse proxy like nginx. The
reverse proxy does the SSL/TLS stuff in that case. But if you want to run Cozy
Proxy with no reverse proxy (low memory server for example), you can set the
following env variables:

```sh
USE_SSL=true
SSL_CRT_PATH=/path/to/server.crt  # /etc/cozy/server.crt by default
SSL_KEY_PATH=/path/to/server.key  # /etc/cozy/server.key by default
```

To use this when the whole Cozy stack is running, you can add this variables
into the Controller configuration file, `/etc/cozy/controller.json`, as
[explained into the
documentation](https://docs.cozy.io/en/hack/cookbooks/controller.html#configuration).
Just add the following lines into this file:

```json
"env": {
  "proxy": {
    "PORT": 443,
    "USE_SSL": true,
    "SSL_CRT_PATH": "/path/to/server.crt",
    "SSL_KEY_PATH": "/path/to/server.key"
  }
}
```

## Hack

To be hacked, the Cozy Proxy dev environment requires that a CouchDB instance
and a Cozy Data System instance are running. Then you can start the Cozy Proxy
this way:

```sh
$ git clone https://github.com/cozy/cozy-proxy.git
$ cd cozy-proxy
$ npm install
$ npm run watch
```

### To hack cozy-proxy using the cozy vagrant

- Forward cozy-home application port from the virtual machine: `config.vm.network :forwarded_port, guest: 9103, host: 9103` in file Vagrantfile
- On your computer, go to your cozy-proxy folder `cd your-cozy-proxy-folder`
- Run `npm install`
- Once install is done, launch cozy-proxy `PORT=9555 HOST="0.0.0.0" npm run watch` (You may use another port)
- You can now access the hacked proxy on `http://localhost:9555` with your navigator

## Tests

![Build Status](https://travis-ci.org/cozy/cozy-proxy.png?branch=master)

To run tests, type the following command into the Cozy Proxy folder:

{'fraction_non_alphanumeric': 0.10738255033557047, 'fraction_numerical': 0.008820709491850431, 'mean_word_length': 4.200398803589232, 'pattern_counts': {'":': 12, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 14, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3415881', 'n_tokens_mistral': 1716, 'n_tokens_neox': 1624, 'n_words': 620}