This repository has been archived by the owner on Aug 30, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
69 lines (57 loc) · 1.75 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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""A simple flask based API for http://infolanka.com/news/ (by chehanr)."""
from flasgger import Swagger
from flask import Flask, render_template
from flask_compress import Compress
from flask_cors import CORS, cross_origin
from flask_limiter import Limiter
from flask_limiter.util import get_remote_address
from decouple import config
from api.v1.routes import API as api_v1
from api.v2.routes import API as api_v2
COMPRESS_MIMETYPES = ['text/html', 'text/css', 'text/xml',
'application/json', 'application/javascript']
COMPRESS_LEVEL = 6
COMPRESS_MIN_SIZE = 500
TEMPLATE = {
'swagger': '2.0',
'info': {
'title': 'newsreadr-api',
'description': 'A simple flask based API for http://infolanka.com/news/',
'contact': {
'name': 'chehanr',
'url': 'https://chehanr.github.io',
},
'version': '0.0.1'
},
"basePath": "/",
'schemes': [
'http',
'https'
]
}
APP = Flask(__name__)
APP.register_blueprint(api_v1, url_prefix='/api/v1')
APP.register_blueprint(api_v2, url_prefix='/api/v2')
# TODO make changes to rate limit.
LIMITER = Limiter(APP, key_func=get_remote_address,
default_limits=['20 per second', '10000 per day'])
APP.config['SWAGGER'] = {
'title': 'API Documentation',
'uiversion': 2
}
SWAG = Swagger(APP, template=TEMPLATE)
Compress(APP)
CORS(APP)
@APP.route('/')
def root():
"""Show index page."""
return render_template('index.html')
@APP.route('/api/')
def api_root():
"""Show api information."""
return render_template('api.html')
if __name__ == '__main__':
APP.run(debug=config('DEBUG', default=False,
cast=bool), use_reloader=True)