Skip to content

Commit

Permalink
fix(example): next.js production runtime error (#280)
Browse files Browse the repository at this point in the history
  • Loading branch information
zhanshuyou authored Feb 27, 2024
1 parent 6652fee commit 39ea256
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 15 deletions.
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);
}

0 comments on commit 39ea256

Please sign in to comment.