1
+ /**
2
+ * Nautilus Trusted Compute
3
+ * Copyright (C) 2025 Nautilus
4
+ *
5
+ * This program is free software: you can redistribute it and/or modify
6
+ * it under the terms of the GNU Affero General Public License as published
7
+ * by the Free Software Foundation, either version 3 of the License, or
8
+ * (at your option) any later version.
9
+ *
10
+ * This program is distributed in the hope that it will be useful,
11
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ * GNU Affero General Public License for more details.
14
+ *
15
+ * You should have received a copy of the GNU Affero General Public License
16
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
17
+ */
18
+
19
+ // app/api/execute-python/route.ts
20
+ import { NextRequest , NextResponse } from 'next/server' ;
21
+ import fetch from 'node-fetch' ;
22
+ import https from 'https' ;
23
+
24
+ export async function POST ( req : NextRequest ) {
25
+ try {
26
+ const { publicIp, github_url, expected_hash } = await req . json ( ) ;
27
+
28
+ if ( ! publicIp || ! github_url || ! expected_hash ) {
29
+ return NextResponse . json ( { error : 'Missing publicIp, github_url, or expected_hash' } , { status : 400 } ) ;
30
+ }
31
+
32
+ const url = `https://${ publicIp } /execute_python` ;
33
+
34
+ const response = await fetch ( url , {
35
+ method : 'POST' ,
36
+ headers : {
37
+ 'Content-Type' : 'application/json' ,
38
+ } ,
39
+ body : JSON . stringify ( { github_url, expected_hash } ) ,
40
+ agent : new https . Agent ( {
41
+ rejectUnauthorized : false , // Ignore self-signed certificate
42
+ } ) ,
43
+ } as any ) ; // Temporary type assertion
44
+
45
+ if ( ! response . ok ) {
46
+ const errorText = await response . text ( ) ;
47
+ return NextResponse . json ( { error : `Enclave error: ${ errorText } ` } , { status : response . status } ) ;
48
+ }
49
+
50
+ const result = await response . json ( ) ; // Expecting JSON output from Python execution
51
+ return NextResponse . json ( { result } ) ;
52
+ } catch ( error ) {
53
+ console . error ( 'Proxy error:' , error ) ;
54
+ return NextResponse . json ( { error : 'Failed to proxy request to enclave' } , { status : 500 } ) ;
55
+ }
56
+ }
0 commit comments