Testar olika metoder för att hantera Cross-Origin Resource Sharing

This commit is contained in:
Joakim Persson
2024-07-17 14:31:39 +02:00
parent 4f4d9af67d
commit c82f603d51
+5 -1
View File
@@ -2,15 +2,19 @@
# 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
#import requests
#import threading
# Initialize a Flask application
app = Flask(__name__)
CORS(app)
# @app.route('/api/chat', methods=['POST'])
# @cross_origin(origin='http://localhost:8000', headers=['Content-Type']) # Allow cross-origin requests from localhost:8000
@app.route('/api/chat', methods=['POST'])
@cross_origin(origin='*', headers=['Content-Type']) # Enable CORS for this route. Probably not necessary.
def chat():
if request.method == 'POST':
# Get the message from the JSON in the request body
data = request.get_json()
message = data.get('query')