Commit 1bca47c6295780a4b297770e001aeb9d08041db9
1 parent
761a3ec0
Exists in
master
Configuração do servidor para rodar no Apache.
Showing
37 changed files
with
74 additions
and
18 deletions
Show diff stats
... | ... | @@ -0,0 +1,28 @@ |
1 | +<VirtualHost *:80> | |
2 | + ServerName localhost | |
3 | + | |
4 | + WSGIDaemonProcess corretor user=user1 group=group1 threads=5 | |
5 | + WSGIScriptAlias /corretor-backend <path-to-project>/contrib/corretor.wsgi | |
6 | + | |
7 | + <Directory <path-to-project>> | |
8 | + WSGIProcessGroup corretor | |
9 | + WSGIApplicationGroup %{GLOBAL} | |
10 | + Order deny,allow | |
11 | + Allow from all | |
12 | + Require all granted | |
13 | + </Directory> | |
14 | + | |
15 | + Alias /corretor <path-to-project>/view | |
16 | + <Directory <path-to-project>/view> | |
17 | + Order deny,allow | |
18 | + Allow from all | |
19 | + Require all granted | |
20 | + </Directory> | |
21 | + | |
22 | + Header set Access-Control-Allow-Origin "*" | |
23 | + | |
24 | + ServerAdmin webmaster@localhost | |
25 | + | |
26 | + ErrorLog ${APACHE_LOG_DIR}/error.log | |
27 | + CustomLog ${APACHE_LOG_DIR}/access.log combined | |
28 | +</VirtualHost> | ... | ... |
... | ... | @@ -0,0 +1,11 @@ |
1 | +# Check the official documentation http://flask.pocoo.org/docs/deploying/mod_wsgi/ | |
2 | +# Activate the virtual env (we assume that virtualenv is in the env folder) | |
3 | +activate_this = '<path-to-project>/env/bin/activate_this.py' | |
4 | +execfile(activate_this, dict(__file__=activate_this)) | |
5 | +import logging, sys | |
6 | +sys.stdout = sys.stderr | |
7 | +logging.basicConfig(stream=sys.stderr) | |
8 | +sys.path.insert(0,'<path-to-project>') | |
9 | + | |
10 | +# Run the web-app | |
11 | +from main import app as application | ... | ... |
corretor.py
... | ... | @@ -39,10 +39,11 @@ class Corretor: |
39 | 39 | |
40 | 40 | def __update_project_info(self, project): |
41 | 41 | template = self.env.get_template('template.html') |
42 | - project.info['task_presenter'] = template.render(server=self.config['HOST_ENDPOINT'], app_shortname=self.config['PYBOSSA_APP_SHORT_NAME']) | |
42 | + project.info['task_presenter'] = template.render(server=self.config['HOST_STATIC_FILES_ENDPOINT'], server_backend=self.config['HOST_ENDPOINT'], app_shortname=self.config['PYBOSSA_APP_SHORT_NAME']) | |
43 | 43 | project.info['thumbnail'] = self.config['HOST_ENDPOINT'] + "/img/thumbnail.png" |
44 | 44 | project.info['sched'] = "incremental" |
45 | 45 | project.allow_anonymous_contributors = False |
46 | + #project.published = True | |
46 | 47 | pbclient.update_project(project) |
47 | 48 | |
48 | 49 | def __find_task(self, project_id, task_id): | ... | ... |
main.py
... | ... | @@ -7,15 +7,8 @@ import os |
7 | 7 | import pyutil |
8 | 8 | |
9 | 9 | app = Flask(__name__) |
10 | -CORS(app) | |
11 | 10 | controller = None |
12 | 11 | |
13 | -@app.route("/<path:path>") | |
14 | -def send_static_files(path): | |
15 | - root_dir = os.path.abspath(os.path.dirname(__file__)) | |
16 | - file_dir = os.path.join(root_dir, "view") | |
17 | - return send_from_directory(file_dir, path) | |
18 | - | |
19 | 12 | @app.route("/update_project") |
20 | 13 | def update_project(): |
21 | 14 | try: |
... | ... | @@ -61,18 +54,35 @@ def read_settings(app): |
61 | 54 | config_path = os.path.join(os.path.dirname(here), 'settings_local.py') |
62 | 55 | if os.path.exists(config_path): |
63 | 56 | app.config.from_pyfile(config_path) |
64 | - app.config['HOST_ENDPOINT'] = "http://" + app.config['SERVER_HOST'] + ":" + str(app.config['SERVER_PORT']) | |
57 | + | |
58 | + if app.config['APACHE_HOST']: | |
59 | + app.config['HOST_ENDPOINT'] = "http://" + app.config['SERVER_HOST'] + app.config['APACHE_HOST_ENDPOINT'] | |
60 | + app.config['HOST_STATIC_FILES_ENDPOINT'] = "http://" + app.config['SERVER_HOST'] + app.config['APACHE_STATIC_FILES_ENDPOINT'] | |
61 | + else: | |
62 | + app.config['HOST_ENDPOINT'] = "http://" + app.config['SERVER_HOST'] + ":" + str(app.config['SERVER_PORT']) | |
63 | + app.config['HOST_STATIC_FILES_ENDPOINT'] = app.config['HOST_ENDPOINT'] | |
65 | 64 | |
66 | 65 | def setup_controller(): |
67 | 66 | global controller |
68 | 67 | read_settings(app) |
69 | 68 | env = Environment(loader=PackageLoader('main', 'view')) |
70 | 69 | controller = Corretor(app.config, env) |
70 | + | |
71 | +def setup_static_files_service(app): | |
72 | + if not app.config['APACHE_HOST']: | |
73 | + CORS(app) | |
74 | + @app.route("/<path:path>") | |
75 | + def send_static_files(path): | |
76 | + root_dir = os.path.abspath(os.path.dirname(__file__)) | |
77 | + file_dir = os.path.join(root_dir, "view") | |
78 | + return send_from_directory(file_dir, path) | |
71 | 79 | |
72 | 80 | def run(): |
73 | - setup_controller() | |
74 | 81 | app.run(host=app.config['SERVER_HOST'], port=app.config['SERVER_PORT']) |
75 | 82 | |
83 | +setup_controller() | |
84 | +setup_static_files_service(app) | |
85 | + | |
76 | 86 | if __name__ == '__main__': |
77 | 87 | try: |
78 | 88 | run() | ... | ... |
settings_local.py.tmpl
... | ... | @@ -5,6 +5,11 @@ SERVER_PORT = 8000 |
5 | 5 | AGREEMENT_NUMBER = 2 |
6 | 6 | UPLOAD_FOLDER = "<path-to-corretor>/view/uploads" |
7 | 7 | |
8 | +# Apache Configuration | |
9 | +APACHE_HOST = False | |
10 | +APACHE_HOST_ENDPOINT = "/corretor-backend" | |
11 | +APACHE_STATIC_FILES_ENDPOINT = "/corretor" | |
12 | + | |
8 | 13 | # PyBossa Configuration |
9 | 14 | PYBOSSA_APP_NAME = "Corretor de Sinais" |
10 | 15 | PYBOSSA_APP_SHORT_NAME = "corretor_sinais" | ... | ... |
1 | 1 | (function(corretor, $, undefined) { |
2 | 2 | |
3 | 3 | var base_url = ""; |
4 | + var server_backend_url = ""; | |
4 | 5 | var videos_url = "/videos/"; |
5 | 6 | var uploads_url = "/uploads/"; |
6 | 7 | var upload_session_id = _getUploadSessionID(); |
... | ... | @@ -91,14 +92,14 @@ |
91 | 92 | $("#fix-button").hide(); |
92 | 93 | } |
93 | 94 | |
94 | - function setupButtons(task, deferred) { | |
95 | + function _setupGUI(task, deferred) { | |
95 | 96 | _disableFinishButton(); |
96 | 97 | _resetUploadProgress(); |
97 | 98 | $("#upload-file-name").text("Escolha um arquivo"); |
98 | 99 | $("#file-upload").val(""); |
99 | 100 | $("#file-upload").fileupload( |
100 | 101 | { |
101 | - url : base_url + "/upload", | |
102 | + url : server_backend_url + "/upload", | |
102 | 103 | formData : { |
103 | 104 | "upload_session_id" : upload_session_id, |
104 | 105 | 'sign_name' : task.info.sign_name |
... | ... | @@ -167,7 +168,7 @@ |
167 | 168 | _enableLoading(); |
168 | 169 | $.ajax({ |
169 | 170 | type : "POST", |
170 | - url : base_url + "/render_video", | |
171 | + url : server_backend_url + "/render_video", | |
171 | 172 | data : { |
172 | 173 | "upload_session_id" : upload_session_id, |
173 | 174 | "sign_name" : task.info.sign_name |
... | ... | @@ -188,7 +189,7 @@ |
188 | 189 | _enableLoading(); |
189 | 190 | $.ajax({ |
190 | 191 | type : "POST", |
191 | - url : base_url + "/finish_task", | |
192 | + url : server_backend_url + "/finish_task", | |
192 | 193 | data : { |
193 | 194 | "task_id" : task.id, |
194 | 195 | "project_id" : task.project_id, |
... | ... | @@ -259,7 +260,7 @@ |
259 | 260 | pybossa.presentTask(function(task, deferred) { |
260 | 261 | if (!$.isEmptyObject(task) && current_task_id != task.id) { |
261 | 262 | _loadTaskInfo(task, deferred); |
262 | - setupButtons(task, deferred); | |
263 | + _setupGUI(task, deferred); | |
263 | 264 | $("#success").hide(); |
264 | 265 | $("#main-container").fadeIn(500); |
265 | 266 | } else { |
... | ... | @@ -274,8 +275,9 @@ |
274 | 275 | } |
275 | 276 | |
276 | 277 | // Public methods |
277 | - corretor.run = function(serverhost, projectname) { | |
278 | + corretor.run = function(serverhost, serverbackend, projectname) { | |
278 | 279 | base_url = serverhost; |
280 | + server_backend_url = serverbackend; | |
279 | 281 | videos_url = base_url + videos_url; |
280 | 282 | uploads_url = base_url + uploads_url; |
281 | 283 | _run(projectname); | ... | ... |
view/template.html
... | ... | @@ -68,7 +68,6 @@ |
68 | 68 | style="width: 22px; height: 22px"></img> |
69 | 69 | </a> |
70 | 70 | </div> |
71 | - <!-- <div class="row"></div> --> | |
72 | 71 | <div id="upload-container" class="row"> |
73 | 72 | <h6 id="upload-msg">ENVIAR ARQUIVO DE ANIMAÇÃO BLENDER |
74 | 73 | CORRIGIDO:</h6> |
... | ... | @@ -131,5 +130,5 @@ |
131 | 130 | </div> |
132 | 131 | |
133 | 132 | <script type="text/javascript"> |
134 | - corretor.run("{{ server }}", "{{ app_shortname }}"); | |
133 | + corretor.run("{{ server }}", "{{ server_backend }}", "{{ app_shortname }}"); | |
135 | 134 | </script> | ... | ... |
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type