Skip to content

Commit f2bbfe8

Browse files
committed
UPDATE: add status.json
1 parent a693684 commit f2bbfe8

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

app/routes/status[.]json.tsx

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import type { LoaderFunctionArgs } from "@remix-run/node";
2+
3+
export async function loader({
4+
request,
5+
}: LoaderFunctionArgs) {
6+
7+
const jsonStr = JSON.stringify({
8+
success: true,
9+
message: 'OK',
10+
timestamp: new Date().toISOString(),
11+
tech: `NodeJS ${process.version}`,
12+
lastmod: process.env.LASTMOD || '(not set)',
13+
commit: process.env.COMMIT || '(not set)',
14+
});
15+
16+
const u = new URL(request.url);
17+
const callback = u.searchParams.get('callback');
18+
if (callback && /^[a-zA-Z_][a-zA-Z0-9_]*$/.test(callback)) {
19+
return new Response(`${callback}(${jsonStr});`, {
20+
headers: {
21+
"Content-Type": "text/javascript; charset=utf-8",
22+
},
23+
});
24+
} else {
25+
return new Response(jsonStr, {
26+
headers: {
27+
'Access-Control-Allow-Origin': '*',
28+
'Access-Control-Allow-Methods': 'POST, GET',
29+
'Access-Control-Max-Age': '604800',
30+
'Content-Type': 'application/json; charset=utf-8',
31+
},
32+
});
33+
}
34+
}

0 commit comments

Comments
 (0)