Skip to content

Commit

Permalink
Fix API proxy forwarding
Browse files Browse the repository at this point in the history
  • Loading branch information
florimondmanca committed Feb 2, 2022
1 parent 621d188 commit 37bdb82
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 4 deletions.
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
APP_DEBUG="True"
APP_DATABASE_URL="postgresql+asyncpg://user:pass@localhost:5432/${DB:-catalogage}"
7 changes: 5 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,16 @@ serve: #- Serve both the server and the client in parallel
make -j 2 serve-server serve-client

serve-server: #- Run API server
./tools/colorize_prefix.sh [server] 34 "${bin}uvicorn server.main:app --port 3579 --reload --reload-dir server"
./tools/colorize_prefix.sh [server] 34 "${python} -m server.main"

serve-client: #- Run the client
./tools/colorize_prefix.sh [client] 33 "cd client && npm run dev"

serve-prod: #- Serve both the server and the production client in parallel
make -j 2 serve-server serve-prod-client
make -j 2 serve-prod-server serve-prod-client

serve-prod-server: #- Run API server in production mode
APP_DEBUG=False make serve-server

serve-prod-client: #- Run the production client
./tools/colorize_prefix.sh [client] 33 "cd client && npm start"
Expand Down
1 change: 1 addition & 0 deletions docs/fr/demarrage.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ Le serveur de développement est configurable à l'aide des variables d'environn

| Variable | Description | Valeur par défaut |
|---|---|---|
| `APP_DEBUG` | Lance le serveur en mode développement (hot reload activé, etc) | `False` |
| `APP_DATABASE_URL` | URL vers la base de données PostgreSQL | `postgresql+asyncpg://localhost:5432/catalogage` |

Définissez les valeurs spécifiques à votre situation dans un fichier `.env` placé à la racine du projet, que vous pouvez créer à partir du modèle `.env.example`.
Expand Down
20 changes: 20 additions & 0 deletions docs/fr/ops.md
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,26 @@ Il y a probablement soit un problème de configuration de la connexion entre Ngi
~/catalogage $ git log
```

### Nginx pas mis à jour malgré un changement de configuration

Dans ce cas de figure, la configuration Nginx a été modifiée mais une fois le déploiement effectué, vous constatez qu'elle n'a pas pris effet. C'est peut-être que Nginx n'a pas réussi à charger la nouvelle configuration, car celle-ci contient des erreurs.

Sur le serveur, regardez les erreurs ou alertes de Nginx avec :

```
~/ $ sudo nginx -t
```

Exemple de résultat :

```
nginx: [warn] conflicting server name "web1-staging" on 0.0.0.0:80, ignored
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
```

Rechercher ensuite d'où pourraient provenir les problèmes ainsi identifiés.

## Secrets

La gestion des secrets s'appuie sur Ansible Vault.
Expand Down
2 changes: 1 addition & 1 deletion ops/ansible/roles/web/templates/supervisor.conf.j2
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ stdout_logfile=/var/log/client.out.log

[program:server]
directory={{ workdir }}
command={{ workdir }}/venv/bin/gunicorn -w 2 --bind 127.0.0.1:{{ api_port }} -k uvicorn.workers.UvicornWorker server.main:app
command={{ workdir }}/venv/bin/python -m server.main
autostart=true
autorestart=true
stderr_logfile=/var/log/server.err.log
Expand Down
1 change: 1 addition & 0 deletions server/config/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
class Settings(BaseSettings):
# For usage, see: https://pydantic-docs.helpmanual.io/usage/settings/

debug: bool = False
database_url: str = "postgresql+asyncpg://localhost:5432/catalogage"
docs_url: str = "/docs"
testing: bool = False
Expand Down
30 changes: 29 additions & 1 deletion server/main.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,34 @@
from .api.app import create_app
from .config.di import bootstrap
from .config.di import bootstrap, resolve
from .config.settings import Settings

bootstrap()

app = create_app()

if __name__ == "__main__":
import uvicorn

settings = resolve(Settings)

args = ["server.main:app"]

kwargs: dict = {
"port": 3579,
}

if settings.debug:
kwargs.update(
# Enable hot reload during development.
reload=True,
reload_dir=["server"],
)
else:
kwargs.update(
# Production is served behind Nginx.
# Pass proxy headers so Uvicorn properly reads e.g. any mounted root path.
# See: https://www.uvicorn.org/deployment/#running-behind-nginx
proxy_headers=True
)

uvicorn.run(*args, **kwargs)

0 comments on commit 37bdb82

Please sign in to comment.