Skip to content

Commit 8b02ea3

Browse files
committed
add studio
1 parent 07781d7 commit 8b02ea3

File tree

3 files changed

+37
-0
lines changed

3 files changed

+37
-0
lines changed

build.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
'use strict';
2+
3+
const { execSync } = require('child_process');
4+
5+
const opts = {
6+
apiKey: process.env.MONGOOSE_STUDIO_API_KEY
7+
};
8+
console.log('Creating Mongoose studio', opts);
9+
require('@mongoosejs/studio/frontend')(`/.netlify/functions/studio`, true, opts).then(() => {
10+
execSync(`
11+
mkdir -p ./public/studio
12+
cp -r ./node_modules/@mongoosejs/studio/frontend/public/* ./public/studio/
13+
`);
14+
});

netlify/functions/studio.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
'use strict';
2+
3+
const mongoose = require('mongoose');
4+
5+
require('../../src/movies-demo/movies.model');
6+
7+
const handler = require('@mongoosejs/studio/backend/netlify')({
8+
apiKey: process.env.MONGOOSE_STUDIO_API_KEY
9+
}).handler;
10+
11+
let conn = null;
12+
13+
module.exports = {
14+
handler: async function studioHandler(params) {
15+
if (conn == null) {
16+
conn = await mongoose.connect(process.env.MONGODB_CONNECTION_STRING, { serverSelectionTimeoutMS: 3000 });
17+
}
18+
19+
return handler.apply(null, arguments);
20+
}
21+
};

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
{
22
"name": "studio.mongoosejs.io",
33
"dependencies": {
4+
"@mongoosejs/studio": "0.0.77",
45
"tailwindcss": "3.x"
56
},
67
"devDependencies": {
78
"serve": "14.2.4"
89
},
910
"scripts": {
11+
"build": "node ./build",
1012
"postinstall": "npm run tailwind",
1113
"start": "serve ./public",
1214
"tailwind": "tailwindcss -o ./public/tw.css",

0 commit comments

Comments
 (0)