How to create Allowed Origin with environment variable. This my code.
ALLOW_ORIGIN=localhost,mydomain.com
TypeScript
def main(context):
"""
This function is called as an api.
"""
response = {
'message': 'Hello World!',
'api': 'default',
}
if context.req.path == '/v1/list':
data = list_domain()
response['api'] = 'list'
response['data'] = data
headers = {
'Access-Control-Allow-Origin': os.environ['ALLOW_ORIGIN']
}
context.log(headers)
return context.res.json(response, headers=headers)
if context.req.path == '/v1/search':
query_param = context.req.query
domain = query_param['domain']
data = search_domain(domain)
response['api'] = 'search domain'
response['data'] = data
headers = {
'Access-Control-Allow-Origin': os.environ['ALLOW_ORIGIN']
}
return context.res.json(response, headers=headers)
return context.res.empty()
TL;DR
The developer is trying to create an Allowed Origin using an environment variable in their Python 3.9 code. They have set the value of the environment variable in the appwrite dashboard. However, they are still getting a CORS error when using fetch. The code they provided includes a main function that is called as an API. In each API endpoint, they are trying to set the 'Access-Control-Allow-Origin' header using the value of the ALLOW_ORIGIN environment variable. The code looks correct.
Solution: It is important to ensure that the ALLOW_ORIGIN environment variable is correctly set in the appwrite dashboard. Double-check the spelling and make sureThe value of env vars can be set in the appwrite dashboard
I was set. But still getting CORS from fetch.
Recommended threads
- Is it possible to create and update with...
Desde la comunidad latina. Es posible ejecutar un CREATE y un UPDATE , en la misma transacción? mi objetivo es que el ID creado, se coloque en el array del upd...
- Invalid document structure: Unknown attr...
I have a production server running Appwrite 1.7.4. I'm testing Appwrite 1.8.0 on a separate test server. To transfer data from my 1.7.4 installation to 1.8, I ...
- Pool 'console' is empty
I am using self-hosted Appwrite. I recently upgraded to 1.7.4 and because of that I monitored the logs more closely. I noticed the realtime-error **Pool 'consol...