From 80000dd26f003a62b1a3ecfb91ee6216179b1273 Mon Sep 17 00:00:00 2001 From: pepperpepperpepper Date: Mon, 16 Nov 2015 19:51:56 -0800 Subject: added static files for local development --- gallery/index.html | 1 - photoblaster/config.py | 1 + photoblaster/server.py | 28 ++++++++++++++++++---------- 3 files changed, 19 insertions(+), 11 deletions(-) diff --git a/gallery/index.html b/gallery/index.html index 38be9a4..2078dba 100644 --- a/gallery/index.html +++ b/gallery/index.html @@ -115,4 +115,3 @@ Main.init(); - diff --git a/photoblaster/config.py b/photoblaster/config.py index 63b1272..a5230bd 100644 --- a/photoblaster/config.py +++ b/photoblaster/config.py @@ -18,6 +18,7 @@ OUTPUT_IMAGE_TYPES = ["png", "jpg", "gif" ] #mounted on tmpfs WORKING_DIR = "/var/www/cache" +STATIC_FOLDER = "../share/frontend/" #server SERVER_HOST='0.0.0.0' diff --git a/photoblaster/server.py b/photoblaster/server.py index 0baf44b..9ce7e19 100644 --- a/photoblaster/server.py +++ b/photoblaster/server.py @@ -12,10 +12,19 @@ from photoblaster.modules import PbGenerate, PbGrid, PbBreaker, PbPattern,\ PbLandscape, PbGradient, PbProcessError, Pb from photoblaster.db import Db from photoblaster.param import BadParamError -from photoblaster.config import SERVER_HOST, SERVER_PORT +from photoblaster.config import SERVER_HOST, SERVER_PORT, STATIC_FOLDER # FIXME add remote_addr and this jsonp thing +_CLASSNAME_ALIASES = { + 'generate': 'PbGenerate', + 'imgrid': 'PbGrid', + 'imbreak': 'PbBreaker', + 'impattern': 'PbPattern', + 'imgradient': 'PbGradient', + 'landscape': 'PbLandscape', +} + class InvalidUsage(Exception): """error class for InvalidUsage""" @@ -37,8 +46,10 @@ class InvalidUsage(Exception): class Server(object): """Main server class""" def __init__(self): - self.app = Flask(__name__) + # self.app = Flask(__name__) + self.app = Flask(__name__, static_folder=STATIC_FOLDER) self._wsgi_server = None + self._classname_aliases = _CLASSNAME_ALIASES @self.app.route('/test', methods=['GET']) def test(): @@ -65,14 +76,11 @@ class Server(object): response.status_code = error.status_code return response - self._classname_aliases = { - 'generate': 'PbGenerate', - 'imgrid': 'PbGrid', - 'imbreak': 'PbBreaker', - 'impattern': 'PbPattern', - 'imgradient': 'PbGradient', - 'landscape': 'PbLandscape', - } + # Static Routes (for local development only!!!) + @self.app.route('/') + def static_proxy(path): + # send_static_file will guess the correct MIME type + return self.app.send_static_file(path) @self.app.route('/im/data', methods=['GET']) def get_data(): -- cgit v1.2.3-70-g09d2