-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.py
65 lines (48 loc) · 1.45 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
__author__ = 'Deon Hua and Timothy Mui'
import os
from flask import *
from flask_cors import *
import MolarMass
#Configure Flask application + CORS
app = Flask(__name__)
app.config['CORS_HEADERS'] = 'Content-Type'
#Main pages
@app.route("/")
def home():
return render_template("index.html")
@app.route("/conversion.html")
def conversion():
return render_template("conversion.html")
@app.route("/about.html")
def about():
return render_template("about.html")
#API endpoint, allow for CORS requests for flexibility in the future.
@app.route("/postChemFormula", methods=["POST"])
@cross_origin()
def postChemFormula():
post = request.get_json()
app.logger.debug(post)
formula = post.get('formula')
app.logger.debug(formula)
molarMass = MolarMass.get_molar_mass(formula)
if molarMass:
outputMolarMass = "%.3f" %molarMass
app.logger.debug(outputMolarMass)
return outputMolarMass
else:
return ""
#For "Add to Homescreen" for Chrome M39
@app.route("/static/index.html")
def mobileApp():
return render_template("index.html")
#Google stuff
@app.route("/google0dec4c879860ede1.html")
def verify():
return render_template("google0dec4c879860ede1.html")
#404 Page Not Found
@app.errorhandler(404)
def pageNotFound(error):
return render_template("pageNotFound.html"), 404
#Launch Flask app
if __name__ == ("__main__"):
app.run(debug=True,host='0.0.0.0',port=int(os.environ.get("PORT", 5000)))