Skip to content

Commit

Permalink
fix: defined proper cors rules + OFF api call
Browse files Browse the repository at this point in the history
  • Loading branch information
areebahmeddd committed Nov 8, 2024
1 parent cfc595b commit 4075779
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
4 changes: 3 additions & 1 deletion server/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@
# Enable CORS for all routes under /api/*
CORS(app, resources={
r'/api/*': {
'origins': ['*'],
'origins': ['http://localhost:3000', 'https://mivro.org'],
'methods': ['GET', 'POST', 'PUT', 'DELETE'],
'allow_headers': ['Content-Type', 'Authorization'],
'supports_credentials': True
}
})
Expand Down
13 changes: 10 additions & 3 deletions server/search.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Core library imports: Open Food Facts API setup
import openfoodfacts
from openfoodfacts import API, APIVersion, Country, Environment, Flavor
import json
import sys
from flask import Blueprint, Response, request, jsonify
Expand All @@ -13,7 +13,14 @@

# Blueprint for the search routes
search_blueprint = Blueprint('search', __name__)
api = openfoodfacts.API(user_agent='Mivro/1.0') # Initialize the Open Food Facts API client
# Initialize the Open Food Facts API client
api = API(
user_agent='Mivro/1.0',
country=Country.world,
flavor=Flavor.off,
version=APIVersion.v2,
environment=Environment.org,
)

@search_blueprint.route('/barcode', methods=['POST'])
def barcode() -> Response:
Expand Down Expand Up @@ -84,7 +91,7 @@ def barcode() -> Response:
runtime_error('barcode', str(exc), product_barcode=product_barcode)
return jsonify({'error': str(exc)}), 500

# DEPRECATED: text_search function fails to return the expected results from the Open Food Facts API
# DEPRECATED: text_search function fails to return the expected results from the Open Food Facts API (v0.4.0)
# @search_blueprint.route('/text', methods=['POST'])
# def text() -> Response:
# try:
Expand Down

0 comments on commit 4075779

Please sign in to comment.