Skip to content

Commit bdc0d0e

Browse files
committed
ActionsでFunctionsアクセスするときの環境変数を修正
1 parent 720c65a commit bdc0d0e

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

src/for-github-actions/fetchData.ts

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
import { config } from "dotenv";
2+
config();
3+
14
async function fetchData() {
25
const dataType = "forecast";
36
let dataToSend = {};
@@ -25,16 +28,28 @@ async function fetchData() {
2528

2629
// FunctionsのAPIを叩く
2730
try {
28-
const baseUrl = process.env.FUCTIONS_URL;
31+
const jwtToken = process.env.JWT_TOKEN;
32+
if (!jwtToken) {
33+
console.error("JWT_TOKEN is not set");
34+
process.exit(1);
35+
}
36+
const baseUrl = process.env.FUNCTIONS_URL;
37+
if (!baseUrl) {
38+
console.error("FUCTIONS_URL is not set");
39+
process.exit(1);
40+
}
2941
const url = baseUrl + "/forecast";
3042
const res = await fetch(url, {
3143
method: "POST",
3244
headers: {
3345
"Content-Type": "application/json",
34-
Auhtorization: `Bearer ${process.env.JWT_TOKEN}`,
46+
Auhtorization: `Bearer ${jwtToken}`,
3547
},
3648
body: JSON.stringify(dataToSend),
3749
});
50+
if (!res.ok) {
51+
throw new Error(`Failed to save data: ${res.statusText}`);
52+
}
3853
console.log("successfully saved to Firestore:", res);
3954
} catch (error) {
4055
console.error("Error saving data:", error);

0 commit comments

Comments
 (0)