Serve index.html for static directory
This allows to have shorter sao URL because it is without index.html. Also this adds the support of static web root when launching WSGI app from a different WSGI server. issue6677 review45501002
This commit is contained in:
1 parent
0aed819d47
commit
e85a4891ac
3 files changed
+29
-10
No files matched your search
@@ -30,9 +30,6 @@ with commandline.pidfile(options):
|
||||
for name in options.database_names:
|
||||
Pool(name).init()
|
||||
hostname, port = split_netloc(config.get('web', 'listen'))
|
||||
static_files = {
|
||||
'/': config.get('web', 'root'),
|
||||
}
|
||||
certificate = config.get('ssl', 'certificate')
|
||||
privatekey = config.get('ssl', 'privatekey')
|
||||
if certificate or privatekey:
|
||||
@@ -47,6 +44,5 @@ with commandline.pidfile(options):
|
||||
run_simple(hostname, port, app,
|
||||
threaded=True,
|
||||
extra_files=extra_files,
|
||||
static_files=static_files,
|
||||
ssl_context=ssl_context,
|
||||
use_reloader=options.dev)
|
||||
@@ -4,7 +4,6 @@
|
||||
import logging
|
||||
import pydoc
|
||||
|
||||
from werkzeug.utils import redirect
|
||||
from werkzeug.exceptions import abort
|
||||
from sql import Table
|
||||
|
||||
@@ -82,11 +81,6 @@ def root(request, *args):
|
||||
return methods[request.rpc_method](request, *request.rpc_params)
|
||||
|
||||
|
||||
@app.route('/', methods=['GET'])
|
||||
def home(request):
|
||||
return redirect('/index.html') # XXX find a better way
|
||||
|
||||
|
||||
def db_exist(request, database_name):
|
||||
Database = backend.get('Database')
|
||||
try:
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
# this repository contains the full copyright notices and license terms.
|
||||
import httplib
|
||||
import logging
|
||||
import os
|
||||
import sys
|
||||
import traceback
|
||||
|
||||
@@ -9,6 +10,7 @@ from werkzeug.wrappers import Response
|
||||
from werkzeug.routing import Map, Rule
|
||||
from werkzeug.exceptions import abort, HTTPException, InternalServerError
|
||||
from werkzeug.contrib.fixers import ProxyFix
|
||||
from werkzeug.wsgi import SharedDataMiddleware
|
||||
|
||||
import wrapt
|
||||
|
||||
@@ -118,7 +120,34 @@ class TrytondWSGI(object):
|
||||
def __call__(self, environ, start_response):
|
||||
return self.wsgi_app(environ, start_response)
|
||||
|
||||
|
||||
class SharedDataMiddlewareIndex(SharedDataMiddleware):
|
||||
def __call__(self, environ, start_response):
|
||||
if environ['REQUEST_METHOD'] not in {'GET', 'HEAD'}:
|
||||
return self.app(environ, start_response)
|
||||
return super(SharedDataMiddlewareIndex, self).__call__(
|
||||
environ, start_response)
|
||||
|
||||
def get_directory_loader(self, directory):
|
||||
def loader(path):
|
||||
if path is not None:
|
||||
path = os.path.join(directory, path)
|
||||
else:
|
||||
path = directory
|
||||
if os.path.isdir(path):
|
||||
path = os.path.join(path, 'index.html')
|
||||
if os.path.isfile(path):
|
||||
return os.path.basename(path), self._opener(path)
|
||||
return None, None
|
||||
return loader
|
||||
|
||||
|
||||
app = TrytondWSGI()
|
||||
if config.get('web', 'root'):
|
||||
static_files = {
|
||||
'/': config.get('web', 'root'),
|
||||
}
|
||||
app.wsgi_app = SharedDataMiddlewareIndex(app.wsgi_app, static_files)
|
||||
num_proxies = config.getint('web', 'num_proxies')
|
||||
if num_proxies:
|
||||
app.wsgi_app = ProxyFix(app.wsgi_app, num_proxies=num_proxies)
|
||||
|
||||
Reference in new issue
Block a user