def serving_app(request):
    """Create a Flask app and serve it over 8080.

    This will be used to pretend to be GitHub, so we can see test what
    happens when GitHub returns unexpected responses. When the test
    ends, the server is destroyed.
    """
    host = "127.0.0.1"
    port = randint(8000, 8999)
    app = Flask(__name__)

    app.url = "http://{0}:{1}".format(host, port)
    server = ThreadedWSGIServer(host, port, app)
    thread = threading.Thread(target=server.serve_forever)
    thread.start()
    request.addfinalizer(server.shutdown)
    return app
Example #2
0
    return render_template("upload.html")


@app.route("/view/<filename>")
def view(filename):
    return render_template("view.html", filename=filename, url=app.url)


@app.route("/v1/api/upload", methods=["POST"])
def upload():
    if request.method == "POST" and "photo" in request.files:
        rand = hashlib.sha224(request.files["photo"].filename + str(datetime.datetime.now())).hexdigest()[:15] + "."
        filename = photos.save(request.files["photo"], name=rand)
        flash("Photo saved.")
        result = {
            "filename": filename,
            "directurl": app.url + url_for("static", filename=filename),
            "viewurl": app.url + url_for("view", filename=filename),
        }
        return jsonify(result)


if __name__ == "__main__":
    app.debug = True
    app.host = "0.0.0.0"
    app.port = "5000"
    app.url = "https://%s" % platform.uname()[1]
    app.instance_root = "./static/"
    app.secret_key = "7bH6^ugydHVVocwDjCb8y6n.L"
    configure_uploads(app, photos)
    app.run()