从S3提供站点地图以反应静态页面

时间:2017-04-25 21:48:33

标签: ruby-on-rails reactjs redirect amazon-s3

我使用Rails创建我的站点地图并将其托管在React上。我网站的前端基于content_disposition。上传文件的attachmentimport logging logging.basicConfig(filename='wsgi_flask.log', level=logging.DEBUG) try: import sys, os logging.info('line 7') VENV = os.path.join(os.environ['HOME'], '.pyenv', 'versions', '3.5.2', 'envs', 'flask') INTERP = os.path.join(VENV, 'bin', 'python') logging.info('line 12') if sys.executable != INTERP: os.execl(INTERP, INTERP, *sys.argv) logging.info('line 17') sys.path.append(VENV) sys.path.append(os.path.join(VENV, 'lib', 'python3.5', 'site-packages')) sys.path.append(os.path.join(os.environ['HOME'], 'api.example.com')) logging.info('line 23') # INTERP = os.path.join(os.environ['HOME'], '.pyenv', 'versions', 'flask', 'bin', 'python') # if sys.executable != INTERP: # os.execl(INTERP, INTERP, *sys.argv) # sys.path.append(os.getcwd()) from paste.exceptions.errormiddleware import ErrorMiddleware logging.info('line 31') # import argparse import json logging.info('line 36') from flask import (Flask, abort, g, jsonify, make_response, redirect, render_template, render_template_string, request, url_for, Response) logging.info('line 41') # parser = argparse.ArgumentParser() # parser.add_argument('-d', '--debug', action='store_true') # apargs = parser.parse_args() # def debugLog(*args): # if apargs.debug: # for i in args: # print(i) application = Flask(__name__) logging.info('line 54') @application.route('/') def index(): logging.info('line 58') # if apargs.debug: # data = json.load(open('/path/to/test.json', 'rb')) # else: logging.info('line 62') try: logging.info('line 64') data = json.load(open('/path/to/test.json', 'rb')) logging.info('line 66') except: logging.info('line 68') logging.warning('Is it the JSON?') raise('Error whilst loading JSON') logging.info('line 71') getForm = request.args.get('search') or '' logging.info('line 73') # debugLog(data, getForm) jsonData = "" logging.info('line 78') for d in data: logging.info('line 80 (for loop)') # debugLog(d) if getForm in d['text']: logging.info('line 83 (for loop)') jsonData = jsonData + str(d) + ',' logging.info('line 85 (for loop)') logging.info('line 86 (for loop)') logging.info('line 87 (out of loop)') # debugLog(jsonData) jsonData = str(jsonData) logging.info('line 91') jsonData = jsonData[:-1] logging.info('line 93') jsonData = jsonData.replace("'", '"') logging.info('line 95') jsonData = '[' + jsonData + ']' logging.info('line 97') # debugLog('\n', jsonData) return Response(jsonify(json.loads(jsonData)), mimetype='application/json') logging.info('line 101 (this should not show)') @application.errorhandler(500) def error(e): logging.warning(e + '\n\n\n What\'s happening here') return str(e) logging.info('line 107') application = ErrorMiddleware(application, debug=True, error_log='tmp/wsgi_error.log') logging.info('line 109') # if apargs.debug: # application.run(host='0.0.0.0', debug=True, port=80) except: logging.warning('line 114 (beginning of outer most try-except)') import sys, os logging.warning('line 116') from traceback import format_list, extract_tb logging.warning('line 119') (extype, value, trace) = sys.exc_info() logging.warning('line 121') sys.stderr.buffer.write("%s:%s\n%s" % (extype, value,''.join(format_list(extract_tb(trace))))) logging.warning('line 124 (EOF)') ,因此只需转到该网址即可自动下载该文件,或至少为用户提供下载该文件的选项。

有没有办法可以创建一个React页面www.somedomain.com/sitemap.xml.gz哪个会自动从S3调用附件并使其可供下载,以便搜索引擎可以理解它?

0 个答案:

没有答案