File tree Expand file tree Collapse file tree 1 file changed +34
-0
lines changed Expand file tree Collapse file tree 1 file changed +34
-0
lines changed Original file line number Diff line number Diff line change
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 - z A - Z _ ] [ a - z A - Z 0 - 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
+ }
You can’t perform that action at this time.
0 commit comments