forked from tsai/budibase
4 changed files with 5 additions and 64 deletions
@ -1,7 +0,0 @@ |
|||
### Self hosting |
|||
This directory contains utilities that are needed for self hosted platforms to operate. |
|||
These will mostly be utilities, necessary to the operation of the server e.g. storing self |
|||
hosting specific options and attributes to CouchDB. |
|||
|
|||
All the internal operations should be exposed through the `index.js` so importing |
|||
the self host directory should give you everything you need. |
|||
@ -1,44 +0,0 @@ |
|||
const CouchDB = require("../db") |
|||
const env = require("../environment") |
|||
const newid = require("../db/newid") |
|||
|
|||
const SELF_HOST_DB = "self-host-db" |
|||
const SELF_HOST_DOC = "self-host-info" |
|||
|
|||
async function createSelfHostDB(db) { |
|||
await db.put({ |
|||
_id: "_design/database", |
|||
views: {}, |
|||
}) |
|||
const selfHostInfo = { |
|||
_id: SELF_HOST_DOC, |
|||
apiKeyId: newid(), |
|||
} |
|||
await db.put(selfHostInfo) |
|||
return selfHostInfo |
|||
} |
|||
|
|||
exports.init = async () => { |
|||
if (!env.SELF_HOSTED) { |
|||
return |
|||
} |
|||
const db = new CouchDB(SELF_HOST_DB) |
|||
try { |
|||
await db.get(SELF_HOST_DOC) |
|||
} catch (err) { |
|||
// failed to retrieve
|
|||
if (err.status === 404) { |
|||
await createSelfHostDB(db) |
|||
} |
|||
} |
|||
} |
|||
|
|||
exports.getSelfHostInfo = async () => { |
|||
const db = new CouchDB(SELF_HOST_DB) |
|||
return db.get(SELF_HOST_DOC) |
|||
} |
|||
|
|||
exports.getSelfHostAPIKey = async () => { |
|||
const info = await exports.getSelfHostInfo() |
|||
return info ? info.apiKeyId : null |
|||
} |
|||
Loading…
Reference in new issue