forked from vulcand/vulcand-docs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
run-prod.py
30 lines (23 loc) · 783 Bytes
/
run-prod.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
from flask import Flask, request, redirect
import os
from urlparse import urlparse, urlunparse
# set the project root directory as the static folder, you can set others.
app = Flask(__name__, static_url_path='', static_folder='build')
@app.before_request
def redirect_nonhttps():
return
"""Redirect non-www requests to https"""
if request.headers['X-Forwarded-Proto'] == 'https':
return
u = list(urlparse(request.url))
u[0] = 'https'
return redirect(urlunparse(u), code=301)
@app.route('/')
def root():
return app.send_static_file('index.html')
@app.route('/<path:path>')
def static_proxy(path):
# send_static_file will guess the correct MIME type
return app.send_static_file(path)
if __name__ == '__main__':
app.run(port=5501)