Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions app/api/crates/[cratename]/[version]/dependencies/route.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
type Params = Promise<{ cratename: string, version: string }>
import { NextRequest, NextResponse } from "next/server";

export async function GET(req: NextRequest, props: { params: Params }) {
try {
const params = await props.params
const { cratename, version } = params;

const externalApiUrl = `http://210.28.134.203:6888/api/crates/${cratename}/${version}/dependencies`; // 替换为你的外部 API URL
const externalRes = await fetch(externalApiUrl);
if (!externalRes.ok) {
throw new Error('Failed to fetch external data');
}
const externalData = await externalRes.json();
console.log('External API Response:', externalData);
return NextResponse.json(externalData);
} catch (error) {
console.error('Error:', error);
return NextResponse.json({ error: 'Internal Server Error' }, { status: 500 });

}
}
20 changes: 20 additions & 0 deletions app/api/crates/[cratename]/[version]/dependents/route.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { NextRequest, NextResponse } from "next/server";
type Params = Promise<{ cratename: string, version: string }>
export async function GET(req: NextRequest, props: { params: Params }) {
try {
const params = await props.params
const { cratename, version } = params;
const externalApiUrl = `http://210.28.134.203:6888/api/crates/${cratename}/${version}/dependents`; // 替换为你的外部 API URL
const externalRes = await fetch(externalApiUrl);
if (!externalRes.ok) {
throw new Error('Failed to fetch external data');
}
const externalData = await externalRes.json();
console.log('External API Response:', externalData);
return NextResponse.json(externalData);
} catch (error) {
console.error('Error:', error);
return NextResponse.json({ error: 'Internal Server Error' }, { status: 500 });

}
}
22 changes: 22 additions & 0 deletions app/api/crates/[cratename]/[version]/route.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { NextRequest, NextResponse } from "next/server";
type Params = Promise<{ cratename: string, version: string }>

export async function GET(req: NextRequest, props: { params: Params }) {
try {
const params = await props.params
const { cratename, version } = params;

const externalApiUrl = `http://210.28.134.203:6888/api/crates/${cratename}/${version}`; // 替换为你的外部 API URL
const externalRes = await fetch(externalApiUrl);
if (!externalRes.ok) {
throw new Error('Failed to fetch external data');
}
const externalData = await externalRes.json();
console.log('crateinfo 11111111', externalData);
return NextResponse.json(externalData);
} catch (error) {
console.error('Error:', error);
return NextResponse.json({ error: 'Internal Server Error' }, { status: 500 });

}
}
22 changes: 22 additions & 0 deletions app/api/crates/[cratename]/route.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { NextRequest, NextResponse } from 'next/server';
type Params = Promise<{ cratename: string, version: string }>
export async function GET(req: NextRequest, props: { params: Params }) {
try {
const params = await props.params
const { cratename, version } = params;
console.log('cratename', cratename, 'version', version);
const externalApiUrl = `http://210.28.134.203:6888/api/crates/${cratename}`; // 替换为你的外部 API URL
const externalRes = await fetch(externalApiUrl);
if (!externalRes.ok) {
throw new Error('Failed to fetch external data');
}
const externalData = await externalRes.json();

return NextResponse.json(externalData);
} catch (error) {
console.error('Error:', error);
return NextResponse.json({ error: 'Internal Server Error' }, { status: 500 });

}
}

84 changes: 0 additions & 84 deletions app/api/crates/[name]/[version]/route.ts

This file was deleted.

60 changes: 0 additions & 60 deletions app/api/crates/[name]/route.ts

This file was deleted.

10 changes: 5 additions & 5 deletions app/api/crates/route.ts → app/api/crates/route.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import { NextResponse } from 'next/server';
import { NextRequest, NextResponse } from 'next/server';

export async function GET() {
export async function GET(req: NextRequest) {
try {
// 发送 HTTP 请求获取外部数据
const externalApiUrl = 'http://210.28.134.203:6888/crates'; // 替换为你的外部 API URL
console.log(req);
const externalApiUrl = 'http://210.28.134.203:6888/api/crates'; // 替换为你的外部 API URL
const externalRes = await fetch(externalApiUrl);

if (!externalRes.ok) {
throw new Error('Failed to fetch external data');
}

const externalData = await externalRes.json();

return NextResponse.json(externalData);
Expand All @@ -18,3 +17,4 @@ export async function GET() {
return NextResponse.json({ error: 'Internal Server Error' }, { status: 500 });
}
}

19 changes: 19 additions & 0 deletions app/api/cvelist/route.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { NextRequest, NextResponse } from 'next/server';

export async function GET(req: NextRequest) {
try {
// 发送 HTTP 请求获取外部数据
console.log(req);
const externalApiUrl = 'http://210.28.134.203:6888/api/cvelist'; // 替换为你的外部 API URL
const externalRes = await fetch(externalApiUrl);
if (!externalRes.ok) {
throw new Error('Failed to fetch external data');
}
const externalData = await externalRes.json();

return NextResponse.json(externalData);
} catch (error) {
console.error('Error:', error);
return NextResponse.json({ error: 'Internal Server Error' }, { status: 500 });
}
}
3 changes: 2 additions & 1 deletion app/api/cves/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ export async function GET() {
try {
const randomCVEs = Array.from({ length: 7 }, generateRandomCVE);
return NextResponse.json(randomCVEs);
} catch {
} catch (error) {
console.log(error);
return NextResponse.json({ error: 'Internal Server Error' }, { status: 500 });
}
}
32 changes: 32 additions & 0 deletions app/api/search/route.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { NextResponse } from 'next/server';

export async function POST(request: Request) {
const apiUrl = `http://210.28.134.203:6888/api/search`;
const requestBody = await request.json();
console.log("Request Body:", requestBody);

const { query, pagination } = requestBody; //请求体
try {
const response = await fetch(apiUrl, {
method: 'POST',
headers: {
'Content-Type': 'application/json', // 确保发送 JSON
},
body: JSON.stringify({
query, // 发送 query 字段
pagination, // 发送 pagination 字段
}), // 发送 name 字段
});
console.log("response:", response);
if (!response.ok) {
return NextResponse.json({ error: 'Failed to submit data' }, { status: response.status });
}

const result = await response.json(); // 确认返回的是 JSON 格式
console.log("results:", result);
return NextResponse.json({ message: 'Submission successful', code: 2012, data: result });
} catch (error) {
console.log(error);
return NextResponse.json({ error: 'An error occurred while submitting data.' }, { status: 500 });
}
}
30 changes: 15 additions & 15 deletions app/api/submit/route.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
import { NextRequest, NextResponse } from 'next/server';
import { NextResponse } from 'next/server';

export async function POST(request: NextRequest) {
const apiUrl = process.env.API_URL; // 读取环境变量,获取后端服务的基础 URL
const body = await request.json(); // 解析请求体
export async function POST(request: Request) {
const apiUrl = process.env.API_URL; // 读取环境变量
const formData = await request.formData(); // 解析请求体

console.log("Request FormData:", formData);

try {
const response = await fetch(`${apiUrl}/submit`, { //向后端发送服务请求
const response = await fetch(`${apiUrl}`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(body), // 将请求体发送到后端
body: formData, // 保持 FormData
});
//请求失败直接返回

if (!response.ok) {
return NextResponse.json({ error: 'Failed to submit data' }, { status: 500 });
return NextResponse.json({ error: 'Failed to submit data' }, { status: response.status });
}
//解析成功的响应
const result = await response.json();
return NextResponse.json({ message: 'Submission successful', data: result });
} catch {

const result = await response.json(); // 确认返回的是 JSON 格式
return NextResponse.json({ message: 'Submission successful', result });
} catch (error) {
console.log(error);
return NextResponse.json({ error: 'An error occurred while submitting data.' }, { status: 500 });
}
}
Loading