File tree 1 file changed +33
-0
lines changed
1 file changed +33
-0
lines changed Original file line number Diff line number Diff line change
1
+ /**
2
+ * RPC proxy for sending requests to a specified URL.
3
+ * This is useful for sending requests to a Nimiq RPC node from the new
4
+ * Developer Center without the need for CORS.
5
+ */
6
+
7
+ export default defineEventHandler ( async ( event ) => {
8
+ const body = await readBody ( event )
9
+
10
+ if ( ! body . payload )
11
+ throw createError ( { statusCode : 400 , message : 'Missing payload in request body' } )
12
+ if ( ! body . url )
13
+ throw createError ( { statusCode : 400 , message : 'Missing url in request body' } )
14
+
15
+ try {
16
+ const response = await fetch ( body . url , {
17
+ method : 'POST' ,
18
+ headers : { 'Content-Type' : 'application/json' } ,
19
+ body : JSON . stringify ( body . payload ) ,
20
+ } )
21
+
22
+ const data = await response . json ( )
23
+ return data
24
+ }
25
+ catch ( error ) {
26
+ console . error ( 'RPC proxy error:' , error )
27
+ throw createError ( {
28
+ statusCode : 502 ,
29
+ message : 'Failed to connect to RPC node' ,
30
+ cause : error ,
31
+ } )
32
+ }
33
+ } )
You can’t perform that action at this time.
0 commit comments