Untitled
unknown
plain_text
19 days ago
1.0 kB
2
Indexable
Never
from odoo import http from odoo.http import Response class CorsMiddleware(http.Controller): @http.route('/muk_rest/<path:path>', auth='public', csrf=False, methods=['GET', 'POST', 'PUT', 'DELETE', 'OPTIONS']) def catch_all(self, **kwargs): response = Response() response.headers['Access-Control-Allow-Origin'] = '*' response.headers['Access-Control-Allow-Methods'] = 'GET, POST, PUT, DELETE, OPTIONS' response.headers['Access-Control-Allow-Headers'] = 'Content-Type, Authorization' # Check for OPTIONS request to handle CORS preflight if http.request.httprequest.method == 'OPTIONS': return response # Process the original request response.data = self.process_request(**kwargs) return response def process_request(self, **kwargs): # Implement the logic to process the original request here # For example, call the corresponding `muk_rest` method return '{"message": "Original request processed"}'
Leave a Comment