Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
ibm
GitHub Repository: ibm/watson-machine-learning-samples
Path: blob/master/cloud/ai-service-apps/nextjs-carbon-react-ui/src/app/api/deployment/route.js
6410 views
1
import { NextResponse } from "next/server";
2
import { URLS, getToken } from "../../lib/util";
3
4
export async function GET() {
5
try {
6
const token = await getToken();
7
8
const options = {
9
method: "GET",
10
headers: {
11
Authorization: `Bearer ${token}`,
12
Accept: "application/json",
13
},
14
};
15
16
const response = await fetch(URLS.deploymentUrl, options);
17
18
if (!response.ok) {
19
throw new Error("Unexpected response from get-deployment: " + (await response.text()));
20
}
21
const result = await response.json();
22
const fields = {
23
name: result.entity.name,
24
description: result.entity.description,
25
avatar_color: result.entity.custom?.avatar_color,
26
avatar_icon: result.entity.custom?.avatar_icon,
27
placeholder_image: result.entity.custom?.placeholder_image,
28
sample_questions: result.entity.custom?.sample_questions,
29
};
30
return NextResponse.json(fields);
31
} catch (err) {
32
console.error(err);
33
return NextResponse.json({ error: err.message }, { status: 500 });
34
}
35
}
36
37