mirror of
https://github.com/vercel/next.js.git
synced 2026-09-20 02:25:18 +08:00
4466ba436b
## Description This PR ensures that the default prettier config is used for examples and templates. This config is compatible with `prettier@3` as well (upgrading prettier is bigger change that can be a future PR). ## Changes - Updated `.prettierrc.json` in root with `"trailingComma": "es5"` (will be needed upgrading to prettier@3) - Added `examples/.prettierrc.json` with default config (this will change every example) - Added `packages/create-next-app/templates/.prettierrc.json` with default config (this will change every template) ## Related - Fixes #54402 - Closes #54409
66 lines
1.5 KiB
JavaScript
66 lines
1.5 KiB
JavaScript
import * as couchbase from "couchbase";
|
|
|
|
const COUCHBASE_USER = process.env.COUCHBASE_USER;
|
|
const COUCHBASE_PASSWORD = process.env.COUCHBASE_PASSWORD;
|
|
const COUCHBASE_ENDPOINT = process.env.COUCHBASE_ENDPOINT || "localhost";
|
|
const COUCHBASE_BUCKET = process.env.COUCHBASE_BUCKET || "travel-sample";
|
|
let IS_CLOUD_INSTANCE = process.env.IS_CLOUD_INSTANCE || "false";
|
|
|
|
if (!COUCHBASE_USER) {
|
|
throw new Error(
|
|
"Please define the COUCHBASE_USER environment variable inside .env.local",
|
|
);
|
|
}
|
|
|
|
if (!COUCHBASE_PASSWORD) {
|
|
throw new Error(
|
|
"Please define the COUCHBASE_PASSWORD environment variable inside .env.local",
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Global is used here to maintain a cached connection across hot reloads
|
|
* in development. This prevents connections growing exponentially
|
|
* during API Route usage.
|
|
*/
|
|
let cached = global.couchbase;
|
|
|
|
if (!cached) {
|
|
cached = global.couchbase = { conn: null };
|
|
}
|
|
|
|
async function createCouchbaseCluster() {
|
|
if (cached.conn) {
|
|
return cached.conn;
|
|
}
|
|
|
|
cached.conn = await couchbase.connect(
|
|
"couchbase://" +
|
|
COUCHBASE_ENDPOINT +
|
|
(IS_CLOUD_INSTANCE === "true"
|
|
? "?ssl=no_verify&console_log_level=5"
|
|
: ""),
|
|
{
|
|
username: COUCHBASE_USER,
|
|
password: COUCHBASE_PASSWORD,
|
|
},
|
|
);
|
|
|
|
return cached.conn;
|
|
}
|
|
|
|
export async function connectToDatabase() {
|
|
const cluster = await createCouchbaseCluster();
|
|
|
|
const bucket = cluster.bucket(COUCHBASE_BUCKET);
|
|
const collection = bucket.defaultCollection();
|
|
|
|
let dbConnection = {
|
|
cluster,
|
|
bucket,
|
|
collection,
|
|
};
|
|
|
|
return dbConnection;
|
|
}
|