aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas "Cakeisalie5" Touhey <thomas@touhey.fr>2018-11-02 21:57:16 +0100
committerThomas "Cakeisalie5" Touhey <thomas@touhey.fr>2018-11-02 21:57:16 +0100
commit7b57ac37560b743356747a9360667bbbc707ce62 (patch)
tree5f832b15f501a82fa9ccea5c478c72a32f72a3fa
parentaa862af791b28c173a0699b26e5943b2f46e3716 (diff)
Changed the way the app is launched…\?
-rw-r--r--Procfile2
-rwxr-xr-xapp/__init__.py39
-rwxr-xr-xapp/__main__.py54
3 files changed, 39 insertions, 56 deletions
diff --git a/Procfile b/Procfile
index 689e36a..633f292 100644
--- a/Procfile
+++ b/Procfile
@@ -1 +1 @@
-web: pipenv run python -m app
+web: pipenv run flask run --port $PORT
diff --git a/app/__init__.py b/app/__init__.py
index ea8b4ba..76815f5 100755
--- a/app/__init__.py
+++ b/app/__init__.py
@@ -1,5 +1,42 @@
#!/usr/bin/env python3
-# Nothing here, we just want this folder to be considered as a module.
+import os.path as _path
+
+from flask import Flask as _Flask, render_template as _template, \
+ request as _r
+from textoutpc import tohtml as _translate
+
+__all__ = ["app"]
+
+_gd = lambda x: _path.relpath(_path.join(_path.dirname(__file__), x))
+app = _Flask('textout', root_path = _path.curdir,
+ template_folder = _gd('templates'), static_folder = _gd('static'),
+ static_url_path = '/static')
+
+@app.route('/', methods = ['GET'])
+@app.route('/index.html', methods = ['GET'])
+def _empty_page():
+ """ Page sans entrée. """
+
+ return _template('page.html', result = None, text = '')
+
+@app.route('/index.html', methods = ['POST'])
+def _process_page():
+ """ Page avec entrée. """
+
+ result = None
+ text = ''
+
+ if 'text' in _r.form:
+ text = _r.form['text']
+ result = _translate(text)
+
+ return _template('page.html', result = result, text = text)
+
+@app.route('/guide.html', methods = ['GET'])
+def _guide_page():
+ """ Page de guide. """
+
+ return _template('guide.html')
# End of file.
diff --git a/app/__main__.py b/app/__main__.py
deleted file mode 100755
index f57c9de..0000000
--- a/app/__main__.py
+++ /dev/null
@@ -1,54 +0,0 @@
-#!/usr/bin/env python3
-
-import sys as _sys
-import os.path as _path
-from os import environ as _environ
-
-from flask import Flask as _Flask, render_template as _template, \
- request as _r
-from textoutpc import tohtml as _translate
-
-def _empty_page():
- """ Page sans entrée. """
-
- return _template('page.html', result = None, text = '')
-
-def _process_page():
- """ Page avec entrée. """
-
- if not 'text' in _r.form:
- return _empty_page()
- text = _r.form['text']
- result = _translate(text)
- return _template('page.html', result = result, text = text)
-
-def _guide_page():
- """ Page de guide. """
-
- return _template('guide.html')
-
-def run_app(port, debug = False):
- """ Création, configuration et lancement de l'application. """
-
- gd = lambda x: _path.relpath(_path.join(_path.dirname(__file__),
- x))
- app = _Flask('textout', root_path = _path.curdir,
- template_folder = gd('templates'), static_folder = gd('static'),
- static_url_path = '/static')
-
- # Définition des routes.
-
- app.add_url_rule('/', view_func = _empty_page, methods = ['GET'])
- app.add_url_rule('/index.html', view_func = _empty_page, methods = ['GET'])
- app.add_url_rule('/index.html', view_func = _process_page,
- methods = ['POST'])
- app.add_url_rule('/guide.html', view_func = _guide_page, methods = ['GET'])
-
- # Lancement de l'application.
-
- return app.run(port = port, debug = debug)
-
-if __name__ == '__main__':
- run_app(int(_environ.get('PORT')), True)
-
-# End of file.