From f5e6af37cf6804f6deeccdf9de05a75a7ac2620d Mon Sep 17 00:00:00 2001 From: yackob03 Date: Mon, 18 Nov 2013 19:17:58 -0500 Subject: [PATCH] Fix the nginx config to work with the new snapshots. Fix the snapshot creator to correctly create the request path. --- endpoints/web.py | 13 +++++++++---- nginx.conf | 2 +- util/seo.py | 7 +++---- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/endpoints/web.py b/endpoints/web.py index 188533721..625c6d58d 100644 --- a/endpoints/web.py +++ b/endpoints/web.py @@ -4,15 +4,18 @@ import stripe from flask import (abort, redirect, request, url_for, render_template, make_response, Response) -from flask.ext.login import login_user, UserMixin, login_required -from flask.ext.principal import identity_changed, Identity, AnonymousIdentity +from flask.ext.login import login_user, UserMixin +from flask.ext.principal import identity_changed +from urlparse import urlparse from data import model from app import app, login_manager, mixpanel -from auth.permissions import QuayDeferredPermissionUser, AdministerOrganizationPermission +from auth.permissions import (QuayDeferredPermissionUser, + AdministerOrganizationPermission) from util.invoice import renderInvoiceToPdf from util.seo import render_snapshot + logger = logging.getLogger(__name__) @@ -54,7 +57,9 @@ def index(path): @app.route('/snapshot/', methods=['GET']) @app.route('/snapshot/', methods=['GET']) def snapshot(path = ''): - result = render_snapshot(path) + parsed = urlparse(request.url) + final_url = '%s://%s/%s' % (parsed.scheme, 'localhost', path) + result = render_snapshot(final_url) if result: return result diff --git a/nginx.conf b/nginx.conf index 7b1b3074f..cc97cf299 100644 --- a/nginx.conf +++ b/nginx.conf @@ -45,7 +45,7 @@ http { ssl_prefer_server_ciphers on; if ($args ~ "_escaped_fragment_") { - rewrite ^ /static/snapshots$uri/index.html; + rewrite ^ /snapshot$uri; } location /static/ { diff --git a/util/seo.py b/util/seo.py index c44d2a9ea..8a4514b3b 100644 --- a/util/seo.py +++ b/util/seo.py @@ -6,11 +6,10 @@ from bs4 import BeautifulSoup logger = logging.getLogger(__name__) logging.basicConfig(level=logging.DEBUG) -def render_snapshot(path): - final_url = 'http://localhost:5000/' + path - logger.info('Snapshotting url: %s -> %s' % (path, final_url)) +def render_snapshot(url): + logger.info('Snapshotting url: %s' % url) out_html = subprocess.check_output(['phantomjs', '--ignore-ssl-errors=yes', - 'util/phantomjs-runner.js', final_url]) + 'util/phantomjs-runner.js', url]) if not out_html or out_html.strip() == 'Not Found': return None