-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapplication.py
48 lines (35 loc) · 1.46 KB
/
application.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
from flask import Flask
# Begrüßung ausgeben (nur falls die URL mit Parameter aufgerufen wird)
def sag_hallo(name="Welt"):
return '<p>Hallo %s!</p>\n' % name
# Etwas Texts für die Seite
header_text = '''
<html>\n<head> <title>Elastic Beanstalk Flask App</title> </head>\n<body>'''
inhalt = '''
<p>
<em>Hallo!</em>
<br>
AWS Elastic Beanstalk Flask App als Pipeline mit GitHub Actions zum
automatischen Deployment mit Terraform.<br>
Teil des Terraform-Kurses von Datamics.
<br>
</p>\n'''
home_link = '<p><a href="/">Unsere Homepage</a></p>\n'
footer_text = '</body>\n</html>'
# EB schaut per Default automatisch nach einer Callable namens 'application'.
application = Flask(__name__)
# Eine Regel für die Indexseite hinzufügen
application.add_url_rule('/', 'index',
(lambda: header_text +
sag_hallo() + inhalt + footer_text))
# Regel hinzufügen, wenn die URL mit einem Namen aufgerufen wird.
application.add_url_rule('/<name>', 'hallo',
(lambda name:
header_text + sag_hallo(name) + home_link + footer_text))
# App ausführen
if __name__ == "__main__":
# Wird debug auf True gesetzt, so werden Debugging-Nachrichten ausgegeben.
# Dies sollte in Produktion immmer ausgeschaltet sein.
# application.debug = True
# application.run()
application.run(host='0.0.0.0', port=80)