Skip to content

Commit

Permalink
fix: backend server https
Browse files Browse the repository at this point in the history
  • Loading branch information
vaclis_school committed Dec 2, 2024
1 parent 570e4a8 commit 8fa76c6
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 7 deletions.
10 changes: 9 additions & 1 deletion backend/v2/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,18 @@
import matplotlib.pyplot as plt
import seaborn as sns
import time
from fastapi.middleware.cors import CORSMiddleware


# FastAPI 應用
app = FastAPI()

app.add_middleware(
CORSMiddleware,
allow_origins=["*"], # 你可以根據需求設置具體允許的域名
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
# 設定 Google Sheets API 的範圍
SCOPES = ["https://www.googleapis.com/auth/spreadsheets"]

Expand Down
47 changes: 41 additions & 6 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,40 @@
<script>
'use strict';
// const apiEndPoint = 'https://script.google.com/macros/s/AKfycbyEqnJGcnvQN8IDg6mXrvWT78l5U8VpxR7Sp6xuzv299M9UyO5qq5VfmH_2BbfR1IehcQ/exec'; //v1
const apiEndPoint = 'http://www.vaclis.csa.cs.nthu.edu.tw/'; //v2
const apiEndPoint = 'https://www.vaclis.csa.cs.nthu.edu.tw/'; //v2
function subForm(e) {
e.preventDefault();
const userData = $("#myForm").serializeArray();
console.log(userData);

// v1
// $.ajax({
// url: apiEndPoint + '?n=data&t=a',
// type: 'post',
// data: JSON.stringify(userData),
// success: function () {
// alert("Form Data Submitted :)")
// },
// error: function () {
// alert("There was an error :(")
// }
// });
$.ajax({
url: apiEndPoint + '?n=data&t=a',
url: apiEndPoint,
type: 'post',
data: JSON.stringify(userData),
data: JSON.stringify({
n: 'data',
t: 'a',
userData: userData
}),
contentType: "application/json",
success: function () {
alert("Form Data Submitted :)")
},
error: function () {
alert("There was an error :(")
}
});

}

let openedImage, openedImageName;
Expand Down Expand Up @@ -109,10 +126,25 @@
// console.log(userImage);
}

// v1
// function fetchHistoryImage() {
// // $.ajax({ url: apiEndPoint + '?n=image&width=2', success: updateUserImage });
// }
// v2
function fetchHistoryImage() {
$.ajax({ url: apiEndPoint + '?n=image&width=2', success: updateUserImage });
$.ajax({
url: apiEndPoint + '?n=image&width=2',
type: 'get',
success: function (response) {
updateUserImage(response);
},
error: function () {
alert("Failed to fetch history images.");
}
});
}


window.onload = function () {
imagesParentElement = document.getElementById('images');
openedImage = document.getElementById('openedImage');
Expand Down Expand Up @@ -341,7 +373,9 @@ <h2>History Records 歷史紀錄</h2>
<h2>Hitter's History Records Data 打者數據資料</h2>
</header>
<p>
<iframe src="https://docs.google.com/spreadsheets/d/e/2PACX-1vR1Chn7vPQWG6ADxR2hW0qH06dsEOvlHQoWibfPwKQOFmhEjNH2bNmepZuFnlieRQ6D29cKGLbSANzS/pubhtml?widget=true&amp;headers=false" style="width: 100%; height: 76vh;"></iframe>
<iframe
src="https://docs.google.com/spreadsheets/d/e/2PACX-1vR1Chn7vPQWG6ADxR2hW0qH06dsEOvlHQoWibfPwKQOFmhEjNH2bNmepZuFnlieRQ6D29cKGLbSANzS/pubhtml?widget=true&amp;headers=false"
style="width: 100%; height: 76vh;"></iframe>
</p>
</article>

Expand Down Expand Up @@ -438,4 +472,5 @@ <h2>Hitter's History Records Data 打者數據資料</h2>
document.addEventListener("mousedown", closeAllSelect);
</script>
</body>

</html>

0 comments on commit 8fa76c6

Please sign in to comment.