Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Issue-276] fix(example): next.js production runtime error #280

Merged
merged 1 commit into from
Feb 27, 2024
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
18 changes: 3 additions & 15 deletions examples/nextjs/app/page.tsx
Original file line number Diff line number Diff line change
@@ -1,25 +1,13 @@
import { MilvusClient } from '@zilliz/milvus2-sdk-node';

/**
* This option is equivalent to getServerSideProps() in the pages directory.
* https://nextjs.org/docs/app/api-reference/file-conventions/route-segment-config
*/
export const dynamic = 'force-dynamic';

async function getData() {
const milvusClient = new MilvusClient({
address: '10.102.6.196:19530',
});

let res: any = await milvusClient.getMetric({
request: { metric_type: 'system_info' },
});
const HOST = 'http://localhost:3000';

const result = res.response.nodes_info.map((v: any) => {
return v.infos;
});

return result;
async function getData() {
return fetch(HOST + '/api/milvus').then(res => res.json());
}

export default async function Home() {
Expand Down
26 changes: 26 additions & 0 deletions examples/nextjs/pages/api/milvus.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import type { NextApiRequest, NextApiResponse } from 'next';
import { MilvusClient } from '@zilliz/milvus2-sdk-node';

async function getData() {
const milvusClient = new MilvusClient({
address: '10.102.6.196:19530',
});

let res: any = await milvusClient.getMetric({
request: { metric_type: 'system_info' },
});

const result = res.response.nodes_info.map((v: any) => {
return v.infos;
});

return result;
}

export default async function handler(
req: NextApiRequest,
res: NextApiResponse
) {
const data = await getData();
res.status(200).json(data);
}
Loading