Repository navigation
Expand file tree
/
Copy pathindex.js
More file actions
60 lines (50 loc) · 1.93 KB
/
Copy pathindex.js
File metadata and controls
60 lines (50 loc) · 1.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import express from "express";
import dotenv from "dotenv";
dotenv.config();
const app = express();
app.get("/", async (req, res) => {
const authHeader = req.headers.authorization;
const expected = `Bearer ${process.env.AUTH_TOKEN}`;
if (!authHeader || authHeader !== expected) {
return res.status(401).json({ error: "Unauthorized" });
}
const headers = {
"Accept": "application/json",
"Accept-Language": "en",
"Content-Type": "application/json",
"Connection": "keep-alive",
"User-Agent": process.env.TF_SESSION_ID,
"X-Session-Id": process.env.TF_SESSION_ID,
"X-Session-Digest": process.env.TF_SESSION_DIGEST,
"X-Apple-Store-Front": process.env.TF_APPLE_STORE_FRONT,
"X-Apple-TA-Device": process.env.APPLE_DEVICE_MODAL,
"X-Apple-Device-Model": process.env.APPLE_DEVICE_MODAL,
"X-Request-Id": process.env.TF_REQUEST_ID,
"X-Apple-AMD-M": process.env.TF_AMD_M,
};
try {
const response = await fetch(`https://testflight.apple.com/v3/accounts/${process.env.TF_ACCOUNT_ID}/apps`, {
method: "GET",
headers,
});
if (!response.ok) {
return res.status(response.status).json({
error: "TestFlight API error",
status: response.status,
statusText: response.statusText,
});
}
const data = await response.json();
res.setHeader("Content-Type", "application/json");
res.setHeader("Cache-Control", "no-store");
res.send(JSON.stringify(data, null, 2));
} catch (err) {
res.status(502).json({
error: "Failed to reach TestFlight API",
details: err.message,
});
}
});
app.listen(process.env.PORT ?? "3000", () => {
console.log(`Server running on http://localhost:${process.env.PORT}`);
});