import Head from "next/head"; import styles from "../styles/Home.module.css"; import { connectToDatabase } from "../util/couchbase"; export default function Home({ isConnected }) { return (
Create Next App

Welcome to Next.js with Couchbase!

{isConnected ? (

You are connected to Couchbase

) : ( <>

You are NOT connected to Couchbase. Try refreshing the page, and if this error persists check the README.md for instructions.

Note: if the database was recently started, you might have to re-start the app (in dev mode) or re-deploy to your serverless environment for changes to take effect. )}

Get started by editing{" "} pages/index.js

); } export async function getServerSideProps(context) { let connection = await connectToDatabase(); const { collection } = connection; // Check connection with a KV GET operation for a key that doesn't exist let isConnected = false; try { await collection.get("testingConnectionKey"); } catch (err) { // error message will return 'document not found' if and only if we are connected // (but this document is not present, we're only trying to test the connection here) if (err.message === "document not found") { isConnected = true; } // if the error message is anything OTHER THAN 'document not found', the connection is broken } return { props: { isConnected }, }; }