/
app.py
107 lines (72 loc) · 2.11 KB
/
app.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
import os
from bottle import get, static_file, template, run, default_app, request, redirect
DEBUG = os.environ.get('DEBUG', False)
API = 'http://localhost:8080' if DEBUG else 'https://api.onregardequoi.net'
def slash_redirection(*args):
return redirect(request.url + '/')
@get('/')
def index():
return template('template/static/index.html')
@get('/about/')
@get('/about', apply=slash_redirection)
def about():
return template('template/static/about.html')
@get('/sign-up/')
@get('/sign-up', apply=slash_redirection)
def sign_up():
return template('template/static/signup.html', api=API)
@get('/sign-in/')
@get('/sign-in', apply=slash_redirection)
def sign_in():
return template('template/static/signin.html', api=API)
@get('/app/')
def app():
return template('template/app/index.html')
# App static files
@get('/app.js')
def app_js():
return static_file('app.js', root='dist')
@get('/app.js.map')
def app_js_map():
return static_file('app.js.map', root='dist')
@get('/app.css')
def app_css():
return static_file('app.css', root='dist')
@get('/app.css.map')
def app_css_map():
return static_file('app.css.map', root='dist')
# Favicon
@get('/favicon.ico')
def favicon():
return static_file('img/icon/favicon.ico', root='assets')
# SEO static files
@get('/robots.txt')
def robots():
return static_file('seo/robots.txt', root='assets')
@get('/sitemap.xml')
def sitemap():
return static_file('seo/sitemap.xml', root='assets')
# Static assets
@get('/assets/<path:path>')
def static(path):
return static_file(path, root='assets')
# critics
@get('/critic/<movie>/')
@get('/critic/<movie>', apply=slash_redirection)
def critic(movie):
try:
with open(f'assets/critics/{movie}.txt', 'r') as file:
lines = file.readlines()
except IOError:
return about(404, 'Not found')
return template(
'template/static/critic.html',
title=lines[0].strip(),
meta=lines[1].strip(),
image=lines[2].strip(),
body=lines[3:]
)
if DEBUG:
run(host='localhost', port=8081, debug=True)
else:
app = default_app()