commit
4f0d974337
|
@ -11,9 +11,7 @@ module.exports = opts => {
|
||||||
|
|
||||||
const run = async opts => {
|
const run = async opts => {
|
||||||
try {
|
try {
|
||||||
opts.dir = xPlatHomeDir(opts.dir)
|
setup(opts)
|
||||||
const bbconfig = dotenv.config({ path: resolve(opts.dir, ".env") })
|
|
||||||
console.log(bbconfig)
|
|
||||||
await createAppInstance(opts)
|
await createAppInstance(opts)
|
||||||
await createEmptyAppPackage(opts)
|
await createEmptyAppPackage(opts)
|
||||||
exec(`cd ${join(opts.dir, opts.applicationId)} && npm install`)
|
exec(`cd ${join(opts.dir, opts.applicationId)} && npm install`)
|
||||||
|
@ -25,6 +23,13 @@ const run = async opts => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const setup = opts => {
|
||||||
|
opts.dir = xPlatHomeDir(opts.dir)
|
||||||
|
process.env.BUDIBASE_DIR = opts.dir
|
||||||
|
const bbconfig = dotenv.config({ path: resolve(opts.dir, ".env") })
|
||||||
|
console.log(JSON.stringify(bbconfig))
|
||||||
|
}
|
||||||
|
|
||||||
const createAppInstance = async opts => {
|
const createAppInstance = async opts => {
|
||||||
const createAppCtx = {
|
const createAppCtx = {
|
||||||
params: { clientId: process.env.CLIENT_ID },
|
params: { clientId: process.env.CLIENT_ID },
|
||||||
|
@ -45,7 +50,7 @@ const createAppInstance = async opts => {
|
||||||
// this cannot be a top level require as it will cause
|
// this cannot be a top level require as it will cause
|
||||||
// the environment module to be loaded prematurely
|
// the environment module to be loaded prematurely
|
||||||
const instanceController = require("@budibase/server/src/api/controllers/instance")
|
const instanceController = require("@budibase/server/src/api/controllers/instance")
|
||||||
await instanceController.create({
|
const createInstCtx = {
|
||||||
params: {
|
params: {
|
||||||
clientId: process.env.CLIENT_ID,
|
clientId: process.env.CLIENT_ID,
|
||||||
applicationId: opts.applicationId,
|
applicationId: opts.applicationId,
|
||||||
|
@ -53,9 +58,11 @@ const createAppInstance = async opts => {
|
||||||
request: {
|
request: {
|
||||||
body: { name: `dev-${process.env.CLIENT_ID}` },
|
body: { name: `dev-${process.env.CLIENT_ID}` },
|
||||||
},
|
},
|
||||||
})
|
}
|
||||||
|
await instanceController.create(createInstCtx)
|
||||||
|
|
||||||
console.log(chalk.green(`Default Instance Created`))
|
console.log(chalk.green(`Default Instance Created`))
|
||||||
|
console.log(JSON.stringify(createInstCtx.body))
|
||||||
}
|
}
|
||||||
|
|
||||||
const createEmptyAppPackage = async opts => {
|
const createEmptyAppPackage = async opts => {
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
const CouchDB = require("../../db")
|
const CouchDB = require("../../db")
|
||||||
const ClientDb = require("../../db/clientDb")
|
const ClientDb = require("../../db/clientDb")
|
||||||
const { getPackageForBuilder } = require("../../utilities/builder")
|
const { getPackageForBuilder } = require("../../utilities/builder")
|
||||||
const uuid = require("uuid")
|
const newid = require("../../db/newid")
|
||||||
const env = require("../../environment")
|
const env = require("../../environment")
|
||||||
|
|
||||||
exports.fetch = async function(ctx) {
|
exports.fetch = async function(ctx) {
|
||||||
|
@ -24,7 +24,7 @@ exports.create = async function(ctx) {
|
||||||
const db = new CouchDB(ClientDb.name(env.CLIENT_ID))
|
const db = new CouchDB(ClientDb.name(env.CLIENT_ID))
|
||||||
|
|
||||||
const newApplication = {
|
const newApplication = {
|
||||||
_id: uuid.v4().replace(/-/g, ""),
|
_id: newid(),
|
||||||
type: "app",
|
type: "app",
|
||||||
instances: [],
|
instances: [],
|
||||||
userInstanceMap: {},
|
userInstanceMap: {},
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
const CouchDB = require("../../db")
|
const CouchDB = require("../../db")
|
||||||
const client = require("../../db/clientDb")
|
const client = require("../../db/clientDb")
|
||||||
const uuid = require("uuid")
|
const newid = require("../../db/newid")
|
||||||
const env = require("../../environment")
|
const env = require("../../environment")
|
||||||
|
|
||||||
exports.create = async function(ctx) {
|
exports.create = async function(ctx) {
|
||||||
const instanceName = ctx.request.body.name
|
const instanceName = ctx.request.body.name
|
||||||
const uid = uuid.v4().replace(/-/g, "")
|
const appShortId = ctx.params.applicationId.substring(0, 7)
|
||||||
const instanceId = `inst_${ctx.params.applicationId.substring(0, 7)}_${uid}`
|
const instanceId = `inst_${appShortId}_${newid()}`
|
||||||
const { applicationId } = ctx.params
|
const { applicationId } = ctx.params
|
||||||
const clientId = env.CLIENT_ID
|
const clientId = env.CLIENT_ID
|
||||||
const db = new CouchDB(instanceId)
|
const db = new CouchDB(instanceId)
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
const CouchDB = require("../../db")
|
const CouchDB = require("../../db")
|
||||||
const uuid = require("uuid")
|
const newid = require("../../db/newid")
|
||||||
|
|
||||||
exports.fetch = async function(ctx) {
|
exports.fetch = async function(ctx) {
|
||||||
const db = new CouchDB(ctx.params.instanceId)
|
const db = new CouchDB(ctx.params.instanceId)
|
||||||
|
@ -15,7 +15,7 @@ exports.create = async function(ctx) {
|
||||||
const newModel = {
|
const newModel = {
|
||||||
type: "model",
|
type: "model",
|
||||||
...ctx.request.body,
|
...ctx.request.body,
|
||||||
_id: uuid.v4().replace(/-/g, ""),
|
_id: newid(),
|
||||||
}
|
}
|
||||||
|
|
||||||
const result = await db.post(newModel)
|
const result = await db.post(newModel)
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
const CouchDB = require("../../db")
|
const CouchDB = require("../../db")
|
||||||
const Ajv = require("ajv")
|
const Ajv = require("ajv")
|
||||||
const uuid = require("uuid")
|
const newid = require("../../db/newid")
|
||||||
|
|
||||||
const ajv = new Ajv()
|
const ajv = new Ajv()
|
||||||
|
|
||||||
|
@ -9,7 +9,7 @@ exports.save = async function(ctx) {
|
||||||
const record = ctx.request.body
|
const record = ctx.request.body
|
||||||
|
|
||||||
if (!record._rev && !record._id) {
|
if (!record._rev && !record._id) {
|
||||||
record._id = uuid.v4().replace(/-/, "")
|
record._id = newid()
|
||||||
}
|
}
|
||||||
|
|
||||||
// validation with ajv
|
// validation with ajv
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
const { v4 } = require("uuid")
|
||||||
|
|
||||||
|
module.exports = function() {
|
||||||
|
return v4().replace(/-/g, "")
|
||||||
|
}
|
|
@ -3,14 +3,7 @@ const STATUS_CODES = require("../utilities/statusCodes")
|
||||||
const env = require("../environment")
|
const env = require("../environment")
|
||||||
|
|
||||||
module.exports = async (ctx, next) => {
|
module.exports = async (ctx, next) => {
|
||||||
const authHeader = ctx.get("Authorization")
|
if (ctx.path === "/_builder") {
|
||||||
|
|
||||||
if (
|
|
||||||
authHeader &&
|
|
||||||
authHeader.startsWith("Basic") &&
|
|
||||||
authHeader.split(" ")[1] === env.ADMIN_SECRET
|
|
||||||
) {
|
|
||||||
ctx.isAuthenticated = true
|
|
||||||
await next()
|
await next()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue