| 59 | } |
| 60 | |
| 61 | async function sendRequestToRustServer( |
| 62 | repo_url: string, |
| 63 | access_token?: string, |
| 64 | settings?: GourceSettings |
| 65 | ) { |
| 66 | const body: any = { repo_url }; |
| 67 | |
| 68 | if (access_token) { |
| 69 | body.access_token = access_token; |
| 70 | } |
| 71 | |
| 72 | if (settings) { |
| 73 | body.settings = settings; |
| 74 | } |
| 75 | |
| 76 | console.log("Sending request to Rust server:", body); |
| 77 | console.log(`${process.env.API_URL}/start-gource`); |
| 78 | const response = await fetch(`${process.env.API_URL}/start-gource`, { |
| 79 | method: "POST", |
| 80 | headers: { "Content-Type": "application/json" }, |
| 81 | body: JSON.stringify(body), |
| 82 | }); |
| 83 | |
| 84 | if (!response.ok) { |
| 85 | const errorText = await response.text(); |
| 86 | throw new Error( |
| 87 | `HTTP error! status: ${response.status}, message: ${errorText}` |
| 88 | ); |
| 89 | } |
| 90 | |
| 91 | return response.json(); |
| 92 | } |
| 93 | |
| 94 | export async function POST(request: NextRequest) { |
| 95 | try { |