Skip to content

Commit

Permalink
make sync cors work
Browse files Browse the repository at this point in the history
  • Loading branch information
WillJYang committed Apr 14, 2024
1 parent e7f35d5 commit 206ecc1
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 4 deletions.
13 changes: 10 additions & 3 deletions backend/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ def login():
db.collection("Users").document(validation[1]).set(user.__dict__)

if '127.0.0.1' in service:
redirect_url='http://127.0.0.1:5000/dashboard'
#redirect_url='http://127.0.0.1:5000/dashboard'
redirect_url = 'http://127.0.0.1:5000'
else:
redirect_url='https://majoraudit.web.app/dashboard'

Expand Down Expand Up @@ -283,7 +284,7 @@ def get_data():


@app.route('/sync_data', methods = ['POST'])
@cross_origin()
@cross_origin(origins='http://127.0.0.1:5000', supports_credentials=True)
def sync_data():

# if req.method == 'OPTIONS':
Expand All @@ -303,13 +304,19 @@ def sync_data():
#if not netid:
# return redirect('/user_login')

headers = {
'Access-Control-Allow-Credentials': 'true',
'Access-Control-Allow-Origin': 'true'
}

print("here sync data")
print(session["NETID"])

data = request.json
user = User("jy692", data)
db.collection("Users").document("jy692").set(user.__dict__)
print(data, flush=True)

return data
make_response((data, 200, headers))
#return make_response(('Data received', 200, headers))

23 changes: 23 additions & 0 deletions frontend/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@

</div>

<button onclick="syncData()">Sync Data</button>

<button onclick="getData()">Get Data</button>
<div id="dataDisplay"></div>

Expand Down Expand Up @@ -86,6 +88,27 @@
})
}

function syncData() {
var event = new CustomEvent("scrapeData", {
detail: { action: "openWebsite" }
});
document.dispatchEvent(event);
}

document.addEventListener("getData", function(e) {
fetch('http://127.0.0.1:5001/majoraudit/us-central1/functions/sync_data', {
method: 'POST',
mode: 'cors',
credentials: 'include',
headers: {
'Content-Type': 'application/json',
},
body: e.detail
});
console.log(e);

});

$('document').ready(setup);
</script>
</body>
Expand Down
7 changes: 6 additions & 1 deletion scrapers/degreeAuditScraper/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,17 @@
{
"matches": ["http://127.0.0.1:5001/majoraudit/us-central1/functions/dashboard"],
"js": ["majorAuditContent.js"]
},
{
"matches": ["http://127.0.0.1:5000/"],
"js": ["majorAuditContent.js"]
}
],
"host_permissions": [
"https://degreeaudit.yale.edu/responsive/worksheets/WEB31",
"http://localhost:8000/*",
"http://localhost:5001/*"
"http://localhost:5001/*",
"http://127.0.0.1:5000/"
],
"background": {
"service_worker": "background.js"
Expand Down

0 comments on commit 206ecc1

Please sign in to comment.