-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
134 lines (100 loc) · 4.05 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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
# Resize Image App - 2022
# Import Librarys
#import os
import os
from flask import Flask, send_from_directory, session, request, flash, jsonify, redirect, render_template
from flask_cors import CORS, cross_origin
#from datetime import datetime, timedelta
#from flask_sitemap import Sitemap
#from werkzeug.middleware.proxy_fix import ProxyFix
#from flask_talisman import Talisman
#from flask_sslify import SSLify
# Configure application
app = Flask(__name__)
# Wrap Flask app with Talisman
#Talisman(app)
#sslify = SSLify(app)
#app.wsgi_app = ProxyFix(app.wsgi_app, x_proto=1)
CORS(app, support_credentials=True)
# Sitemap
# ext = Sitemap(app=app)
# Ensure templates are auto-reloaded
app.config["TEMPLATES_AUTO_RELOAD"] = True
@app.after_request
def after_request(response):
""" Cache 200 """
#response.headers["Cache-Control"] = "max-age=200"
"""Ensure responses aren't cached"""
response.headers["Cache-Control"] = "no-cache, no-store, must-revalidate"
response.headers["Expires"] = 0
response.headers["Pragma"] = "no-cache"
#response.headers["Access-Control-Expose-Headers"] = "Content-Disposition, Content-Length, X-Content-Transfer-Id"
#response.headers["Content-Type"] = "image/jpeg"
#response.headers["Content-Length"] = "3965123"
#response.headers["Content-Disposition"] = "inline; filename='my-file.jpg'"
#response.headers["X-Content-Transfer-Id"] = "12345"
return response
# Index Page
@app.route("/", methods=["GET", "POST"])
def index():
if request.method == "POST":
# POST method
print("Post method called")
return redirect("/")
else:
# GET method
title = "Free Image Resizer to resize images and photos online"
return render_template('index.html', title=title)
# Contact Page
@app.route("/contact")
def contact_page():
title = "Contact Us - Free Image Resizer"
return render_template('contact.html', title=title)
# Terms Page
@app.route("/terms")
def terms_page():
title = "Terms - Free Image Resizer"
return render_template('terms.html', title=title)
# Other pages
@app.route("/resize-image-to-1080x1080")
def resizeimageto1080x1080_page():
title = "Resize image to 1080x1080 - Free Image Resizer"
return render_template('resize-image-to-1080x1080.html', title=title)
@app.route("/resize-images-for-open-graph-social-media")
def resizeimagesforopengraphsocialmedia_page():
title = "Resize images for Open Graph and Social Media - Free Image Resizer"
return render_template('resize-images-for-open-graph-social-media.html', title=title)
@app.route("/how-to-reduce-jpg-size-online")
def hotworeducejpgsizeonline_page():
title = "How to reduce JPG size online - Free Image Resizer"
return render_template('how-to-reduce-jpg-size-online.html', title=title)
# Sitemap extension
# @ext.register_generator
# def index_sitemap():
# yield 'index', {}
@app.route('/sitemap.xml')
def sitemap_xml():
return send_from_directory(os.path.join(app.root_path, 'static'),'sitemap.xml',mimetype='application/xml')
@app.route('/robots.txt')
def robots_txt():
return send_from_directory(os.path.join(app.root_path, 'static'),'robots.txt',mimetype='text/plain')
@app.route('/ads.txt')
def ads_txt():
return send_from_directory(os.path.join(app.root_path, 'static'),'ads.txt',mimetype='text/plain')
# Favicon
@app.route('/favicon.ico')
def favicon_ico():
return send_from_directory(os.path.join(app.root_path, 'static'),'favicon.ico',mimetype='image/vnd.microsoft.icon')
@app.route('/favicon.png')
def favicon_png():
return send_from_directory(os.path.join(app.root_path, 'static'),'favicon.png',mimetype='image/png')
@app.route('/apple-touch-icon.png')
def AppleTouchIcon():
return send_from_directory(os.path.join(app.root_path, 'static'),
'apple-touch-icon.png',mimetype='image/png')
@app.route('/browserconfig.xml')
def browserconfigXml():
return send_from_directory(os.path.join(app.root_path, 'static'),'browserconfig.xml', mimetype='image/png')
# Debugger mode
if __name__ == '__main__':
app.run(debug=False)