Closed
Description
It is often a good practice to always setup an admin of a database, i.e. at db creation, c.f. #239.
Unfortunately, the following crashes the first time the server is launches (even if one doesn't wait for the callback):
// Create the app.
const app = express();
const expressPouchDB = ExpressPouchDB(PouchDB);
// Set up the admin.
await new Promise((resolve, reject) => {
expressPouchDB.couchConfig.set(
'admins',
config.adminName,
config.adminPassword,
err => {
if (err) reject(err);
else resolve()
}
)
});
// Go.
app.use(expressPouchDB);
app.listen(config.port);
with:
TypeError: refreshUsersDBImpl is not a function
at CouchConfig.refreshUsersDB (/Users/qroy/Workspace/Code/project/node_modules/express-pouchdb/lib/routes/authentication.js:74:12)
at CouchConfig.emit (events.js:182:13)
at /Users/qroy/Workspace/Code/project/node_modules/express-pouchdb/lib/config-infrastructure.js:136:10
at FSReqWrap.oncomplete (fs.js:145:20)
Subsequent launches would work however. It seems the issue is due to the _users
database not being ready yet when the admin is set. Unfortunately, some process still try to update it without waiting.
A somewhat ridiculous workaround is to do this:
// Create the app.
const app = express();
const expressPouchDB = ExpressPouchDB(PouchDB);
// Wait for the _users database to be ready 😔
// (I've tried `await DB('_users').info()` instead without success).
await DB('_users')
.get('whatever')
.catch(() => {});
// Set up the admin.
await new Promise((resolve, reject) => {
expressPouchDB.couchConfig.set(
'admins',
config.adminName,
config.adminPassword,
err => {
if (err) reject(err);
else resolve()
}
)
});
// Go.
app.use(expressPouchDB);
app.listen(config.port);
Metadata
Metadata
Assignees
Labels
No labels