@mongoosejs/studio 0.0.136 → 0.0.138

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -41,6 +41,36 @@ opts.openAIAPIKey = process.env.OPENAI_API_KEY;
41
41
  app.use('/studio', await studio('/studio/api', mongoose, opts));
42
42
  ```
43
43
 
44
+ ### Next.js
45
+
46
+ First, add `withMongooseStudio` to your `next.config.js` file:
47
+
48
+ ```javascript
49
+ import withMongooseStudio from '@mongoosejs/studio/next';
50
+
51
+ // Mount Mongoose Studio frontend on /studio
52
+ export default withMongooseStudio({
53
+ // Your Next.js config here
54
+ reactStrictMode: true,
55
+ });
56
+ ```
57
+
58
+ Then, add `pages/api/studio.js` to your Next.js project to host the Mongoose Studio API:
59
+
60
+ ```javascript
61
+ // Make sure to import the database connection
62
+ import db from '../../src/db';
63
+ import studio from '@mongoosejs/studio/backend/next';
64
+
65
+ const handler = studio({
66
+ apiKey: process.env.MONGOOSE_STUDIO_API_KEY, // optional
67
+ connection: db, // Optional: Connection or Mongoose global. If omitted, will use `import mongoose`
68
+ connectToDB: async () => { /* connection logic here */ }, // Optional: if you need to call a function to connect to the database put it here
69
+ });
70
+
71
+ export default handler;
72
+ ```
73
+
44
74
  ### Netlify
45
75
 
46
76
  [Here is a full example of how to add Mongoose Studio to a Netlify repo](https://github.com/mongoosejs/studio.mongoosejs.io/commit/8b02ea367c8a1b7b4bcab290708f57d58f08210b).