From fcf6db268641ecdd227a9ef76b3cbe64ad12802d Mon Sep 17 00:00:00 2001 From: Joakim Persson Date: Wed, 17 Jul 2024 17:18:05 +0200 Subject: [PATCH] =?UTF-8?q?VIdare=20fels=C3=B6kning=20f=C3=B6r=20att=20f?= =?UTF-8?q?=C3=A5=20CORS=20att=20fungera.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- smartassist/src/backend.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/smartassist/src/backend.py b/smartassist/src/backend.py index b6eb10f..288e9b8 100644 --- a/smartassist/src/backend.py +++ b/smartassist/src/backend.py @@ -2,18 +2,26 @@ # Import the necessary functions from ollama, Flask, requests, threading from ollama import Client from flask import Flask, request, jsonify -from flask_cors import CORS, cross_origin +from flask_cors import CORS, cross_origin # CORS stands for Cross-Origin Resource Sharing. This is necessary to allow the frontend to make requests to our backend. #import requests #import threading # Initialize a Flask application app = Flask(__name__) -CORS(app) +# CORS(app, resources={r"/api/chat": {"origins": "*", "headers": ["Origin", "Content-Type", "Authorization"]}}) # Allow requests from any origin +CORS(app, resources={ + r"/api/chat": { + "origins": "*", + "headers": ["Origin", "Content-Type", "Authorization"], + } +}) # @app.route('/api/chat', methods=['POST']) # @cross_origin(origin='http://localhost:8000', headers=['Content-Type']) # Allow cross-origin requests from localhost:8000 +# @cross_origin(origin='*', headers=['Content-Type']) # Enable CORS for this route. Probably not necessary. +# @cross_origin(origin='*', headers=['Content-Type', 'Accept']) + @app.route('/api/chat', methods=['POST']) -@cross_origin(origin='*', headers=['Content-Type']) # Enable CORS for this route. Probably not necessary. def chat(): # Get the message from the JSON in the request body data = request.get_json()