Python flask_cors.cross_origin() Examples

The following are 4 code examples of flask_cors.cross_origin(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module flask_cors , or try the search function .
Example #1
Source File:    From assembly with MIT License 6 votes vote down vote up
def cors(cls, fn):
        CORS decorator, to make the endpoint available for CORS

        Make sure @cors decorator is placed at the top position.
        All response decorators must be placed below. 
        It's because it requires a response to be available

        class Index(Assembly):
            def index(self):
                return self.render()

            def json(self):
                return {}

        if inspect.isclass(fn):
            raise Error("@cors can only be applied on Assembly methods")
            cors_fn = flask_cors.cross_origin(automatic_options=True)
            return cors_fn(fn) 
Example #2
Source File:    From mrisa with GNU General Public License v2.0 6 votes vote down vote up
def main():
    parser = argparse.ArgumentParser(description='Meta Reverse Image Search API')
    parser.add_argument('-p', '--port', type=int, default=5000, help='port number')
    parser.add_argument('-d','--debug', action='store_true', help='enable debug mode')
    parser.add_argument('-c','--cors', action='store_true', default=False, help="enable cross-origin requests")
    parser.add_argument('-a', '--host', type=str, default='', help="sets the address to serve on")
    args = parser.parse_args()

    if args.debug:
        app.debug = True

    if args.cors:
        CORS(app, resources=r'/search/*')
        app.config['CORS_HEADERS'] = 'Content-Type'

        global search
        search = cross_origin(search)
        print(" * Running with CORS enabled"), port=args.port) 
Example #3
Source File:    From app with MIT License 5 votes vote down vote up
def setup_openid_metadata(app):
    def openid_config():
        res = {
            "issuer": URL,
            "authorization_endpoint": URL + "/oauth2/authorize",
            "token_endpoint": URL + "/oauth2/token",
            "userinfo_endpoint": URL + "/oauth2/userinfo",
            "jwks_uri": URL + "/jwks",
            "response_types_supported": [
                "id_token token",
                "id_token code",
            "subject_types_supported": ["public"],
            "id_token_signing_alg_values_supported": ["RS256"],
            # todo: add introspection and revocation endpoints
            # "introspection_endpoint": URL + "/oauth2/token/introspection",
            # "revocation_endpoint": URL + "/oauth2/token/revocation",

        return jsonify(res)

    def jwks():
        res = {"keys": [get_jwk_key()]}
        return jsonify(res) 
Example #4
Source File:    From chimera with MIT License 4 votes vote down vote up
def server(pipeline_res, host, port, debug=True):
    app = Flask(__name__)

    # @app.route('/', methods=['GET'])
    # @app.route('/index.html', methods=['GET'])
    # def root():
    #     print("got to root")
    #     return app.send_static_file('static/index.html')

    @app.route('/graphs', methods=['GET'])
    def graphs():
        # data = [d.graph.as_rdf() for d in pipeline_res["pre-process"]["train"].data]
        data = [d.graph.as_rdf() for d in pipeline_res["test-corpus"].data]
        return jsonify(data)

    @app.route('/plans/<type>', methods=['POST'])
    def plans(type):
        triplets = request.get_json(force=True)
        graph = Graph(triplets)
        planner = pipeline_res["train-planner"]

        plans = [l.replace("  ", " ")
                     for l in (graph.exhaustive_plan() if type == "full" else graph.plan_all()).linearizations()]
        scores = planner.scores([(graph, p) for p in plans])

        return jsonify({
            "concat": {n: concat_entity(n) for n in graph.nodes},
            "linearizations": list(sorted([{"l": l, "s": s}
                                           for l, s in zip(plans, scores)], key=lambda p: p["s"], reverse=True))

    @app.route('/translate', methods=['POST'])
    def translate():
        req = request.get_json(force=True)
        model = pipeline_res["train-model"]

        return jsonify(model.translate(req["plans"], req["opts"]))

    @app.route('/', defaults={"filename": "index.html"})
    @app.route('/main.js', defaults={"filename": "main.js"})
    @app.route('/style.css', defaults={"filename": "style.css"})
    def serve_static(filename):
        print("Serving static", filename, os.path.join(base_path, 'static'), filename)
        return send_from_directory(os.path.join(base_path, 'static'), filename), host=host, port=port, use_reloader=False, threaded=True)