Skip to content

Commit

Permalink
Fix the fucking functions again - I wish this weren't so painful
Browse files Browse the repository at this point in the history
  • Loading branch information
mawildoer committed Jan 23, 2024
1 parent df926f6 commit 015336b
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@ https://csiandal.medium.com/firebase-function-error-response-is-missing-data-fie

#### CORS

This fixes it right up
There are two ways I've figured out how to get around CORS for the sake of development.

1. `open -n /Applications/Google\ Chrome.app --args --user-data-dir="/var/tmp/chrome-dev-disabled-security" --disable-web-security --disable-site-isolation-trials` and use this browser window

2. Allow a bunch of requests via unsafe headers (not for production)

```python
@https_fn.on_request(
Expand Down
10 changes: 6 additions & 4 deletions functions/main.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
from firebase_admin import initialize_app
from components import *
from package_index import *
import logging
from firebase_admin import initialize_app

logging.basicConfig(level=logging.DEBUG, handlers=[logging.StreamHandler()])

app = initialize_app()


# Last, import all the other functions
from components import *
from package_index import *
6 changes: 3 additions & 3 deletions functions/package_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def get_package(req: https_fn.Request) -> https_fn.Response:
)

# Send back a message that we've successfully written the message
return doc.to_dict()
return {"data": doc.to_dict()}


@https_fn.on_request()
Expand All @@ -41,7 +41,7 @@ def list_packages(req: https_fn.Request) -> https_fn.Response:
"""
db: google.cloud.firestore.Client = firestore.client()
docs = db.collection("packages").stream()
return [doc.to_dict() for doc in docs]
return {"data": [doc.to_dict() for doc in docs]}


@https_fn.on_request()
Expand Down Expand Up @@ -99,4 +99,4 @@ def add_package(req: https_fn.Request) -> https_fn.Response:
)

# Send back a message that we've successfully written the message
return https_fn.Response("Package added")
return https_fn.Response()

0 comments on commit 015336b

Please sign in to comment.