API : first shot

fonctionnel mais il faut que la commande uwsgi -s qui crée le socket soit active dans le shell.
This commit is contained in:
MaelREBOUX 2021-03-30 00:15:25 +02:00
parent c6e67290d1
commit fd46fea548
5 changed files with 107 additions and 0 deletions

65
api/README.md Normal file
View file

@ -0,0 +1,65 @@
# API Ar Redadeg
## À propos
Cette API sert à…
## Installation
### Hello.py
cd api
python3 -m venv venv
. venv/bin/activate
pip install flask uwsgi
tester
python3 hello.py
Vérifier sur http://localhost:5000/
ctrl + C pour arrêter
### Configurer uWSGI
On utilise les fichiers wsgi.py et hello.ini
on teste si uWSGI et le socket fonctionne :
uwsgi -s /tmp/hello.sock --manage-script-name --mount /hello=wsgi:app
### Configurer nginx
On rajoute les directives suivantes au fichier de conf nginx
location = /hello { rewrite ^ /hello/; }
location /hello { try_files $uri @hello; }
location @hello {
include uwsgi_params;
uwsgi_pass unix:/tmp/hello.sock;
}
Recharger la configuration nginx.
Tester http://ar-redadeg.openstreetmap.bzh/hello/
Super ! Mais il faut que la commande uwsgi -s qui crée le socket soit active dans le shell.
### sortir
deactivate
## Sources
https://flask.palletsprojects.com/en/1.1.x/deploying/uwsgi/
https://www.vultr.com/docs/deploy-a-flask-website-on-nginx-with-uwsgi
https://www.digitalocean.com/community/tutorials/how-to-serve-flask-applications-with-uswgi-and-nginx-on-ubuntu-18-04

11
api/hello.ini Normal file
View file

@ -0,0 +1,11 @@
[uwsgi]
module = wsgi:app
master = true
processes = 5
socket = hello.sock
chmod-socket = 660
vacuum = true
die-on-term = true

16
api/hello.py Normal file
View file

@ -0,0 +1,16 @@
#!usr/local/bin/python
# -*- coding: utf-8 -*-
from flask import Flask
app = Flask(__name__)
@app.route("/")
def hello():
return "<h1 style='color:blue'>Hello There!</h1>"
if __name__ == "__main__":
app.debug = True
app.run(host='0.0.0.0')

8
api/wsgi.py Normal file
View file

@ -0,0 +1,8 @@
#!usr/local/bin/python
# -*- coding: utf-8 -*-
from hello import app
if __name__ == "__main__":
app.run()

View file

@ -37,4 +37,11 @@ server {
alias /data/projets/mviewer/;
}
location = /hello { rewrite ^ /hello/; }
location /hello { try_files $uri @hello; }
location @hello {
include uwsgi_params;
uwsgi_pass unix:/tmp/hello.sock;
}
}