Skip to content

Commit

Permalink
cosmosdb
Browse files Browse the repository at this point in the history
  • Loading branch information
solita-nhuttu committed Feb 16, 2024
1 parent 6ac375e commit 0405ae4
Show file tree
Hide file tree
Showing 3 changed files with 170 additions and 5 deletions.
154 changes: 149 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"lint": "next lint"
},
"dependencies": {
"@azure/cosmos": "^4.0.0",
"@azure/storage-blob": "^12.17.0",
"dotenv": "^16.4.1",
"next": "14.1.0",
Expand Down
20 changes: 20 additions & 0 deletions src/app/api/cosmos/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { CosmosClient } from "@azure/cosmos";
import { NextResponse } from "next/server";

const COSMOS_CONNECTION_STRING = process.env.COSMOS_CONNECTION_STRING;
const client = new CosmosClient(COSMOS_CONNECTION_STRING ?? "");
const DB_ID = "nhuttudb";
const CONT_ID = "nhuttucont";

export async function GET(request: Request) {
const db = await client.databases.createIfNotExists({ id: DB_ID });
const cont = await db.database.containers.createIfNotExists({ id: CONT_ID });

const res = {
status: [db.statusCode, cont.statusCode],
endpoints: client.getReadEndpoints(),
de: client.getWriteEndpoints(),
};

return NextResponse.json(res);
}

0 comments on commit 0405ae4

Please sign in to comment.