2 try {
3 // 获取外部URL的内容
4 const response = await fetch("https://esm.town/v/sky_porie_fire443/TestSlime/index.html");
5
6 // 检查是否成功获取
7 if (!response.ok) {
8 throw new Error(`Failed to fetch: ${response.status} ${response.statusText}`);
9 }
10
5async function servePublicFile(path: string): Promise<Response> {
6 const url = new URL("./public/" + path, import.meta.url);
7 const text = await (await fetch(url, {
8 headers: {
9 "User-Agent": "", // to transpile TS to JS
181
182 try {
183 const response = await fetch("/", {
184 method: "POST",
185 body: JSON.stringify({
22app.post("/deploy", verifyGitHubSignature(GITHUB_WEBHOOK_SECRET), deploy);
23
24export default app.fetch;
11
12 try {
13 const response = await fetch("/messages", {
14 method: "POST",
15 headers: { "Content-Type": "application/json" },
22 let text;
23 try {
24 console.log(fetchText(esmURL));
25 text = await fetchText(esmURL);
26 } catch (err) {
27 // if the frontend is expecting .js
31 if (path.endsWith(".js")) {
32 try {
33 text = await fetchText(esmURL.replace(".js", ".ts"));
34 } catch (err) {
35 try {
36 text = await fetchText(esmURL.replace(".js", ".tsx"));
37 } catch (err) {
38 throw new Error("Failed to fetch js/ts/tsx file: " + esmURL);
39 }
40 }
41 } else {
42 throw new Error("Failed to fetch file " + esmURL);
43 }
44 }
46}
47
48async function fetchText(url: string) {
49 const res = await fetch(url, {
50 headers: {
51 // Always transpile TS to JS
55 });
56 if (!res.ok) {
57 throw new Error("Failed to fetch " + url);
58 }
59 return await res.text();
32
33 useEffect(() => {
34 fetchProblem();
35 }, []);
36
37 const fetchProblem = async () => {
38 setLoading(true);
39 try {
40 const response = await fetch("/problem");
41 if (!response.ok) throw new Error("Failed to fetch problem");
42 const data = await response.json();
43 setProblem(data);
49 setFeedbackRenderKey(0);
50 } catch (error) {
51 console.error("Error fetching problem:", error);
52 setFeedback("Failed to load problem. Please try again.");
53 } finally {
60 setLoading(true);
61 try {
62 const response = await fetch("/check", {
63 method: "POST",
64 headers: { "Content-Type": "application/json" },
151 )}
152 {showCorrectAnswer && (
153 <button onClick={fetchProblem} className="next-button">
154 Try a new problem
155 </button>
18 let text;
19 try {
20 text = await fetchText(esmURL);
21 } catch (err) {
22 // if the frontend is expecting .js
26 if (path.endsWith(".js")) {
27 try {
28 text = await fetchText(esmURL.replace(".js", ".ts"));
29 } catch (err) {
30 try {
31 text = await fetchText(esmURL.replace(".js", ".tsx"));
32 } catch (err) {
33 throw new Error("Failed to fetch js/ts/tsx file: " + esmURL);
34 }
35 }
36 } else {
37 throw new Error("Failed to fetch file " + esmURL);
38 }
39 }
41}
42
43async function fetchText(url: string) {
44 const res = await fetch(url, {
45 headers: {
46 // Always transpile TS to JS
50 });
51 if (!res.ok) {
52 throw new Error("Failed to fetch " + url);
53 }
54 return await res.text();
5async function servePublicFile(path: string): Promise<Response> {
6 const url = new URL("./public/" + path, import.meta.url);
7 const text = await (await fetch(url, {
8 headers: {
9 "User-Agent": "", // to transpile TS to JS
181
182 try {
183 const response = await fetch("/", {
184 method: "POST",
185 body: JSON.stringify({