-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
76 lines (66 loc) · 1.77 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
const auth = require('./auth/auth');
const db = require('./db/db');
const accessControl = require('./accessControl');
const Configuration = require('./Configuration');
const { authTokenMiddleware, getTokenEndPoint } = require('./auth/token');
/** @todo Fix https://github.com/neuroanatomy/NeuroWebLab/issues/1 */
let usernameField;
const checkAnyoneUser = () => {
/* check that the 'anyone' user exists. Insert it if it doesn't */
const query = {};
query[usernameField] = 'anyone';
// const query = {username: 'anyone'};
console.log({ fn: 'checkAnyoneUser', query });
db.queryUser(query)
.then((res) => {
console.log('"anyone" user correctly configured.', res);
})
.catch((err) => {
console.log('"anyone" user absent: adding one.', err);
const anyone = {
// username: 'anyone',
name: 'Any User',
joined: (new Date()).toJSON()
};
anyone[usernameField] = 'anyone';
db.addUser(anyone);
});
};
const version = () => 'v0.0.1';
/** @todo Fix https://github.com/neuroanatomy/NeuroWebLab/issues/1 */
const init = async ({
app,
MONGO_DB,
dirname,
usernameField: newUsernameField,
usersCollection,
projectsCollection,
annotationsCollection
}) => {
usernameField = newUsernameField;
console.log({ MONGO_DB });
Configuration.getInstance().setProperties({
usernameField,
usersCollection,
projectsCollection,
annotationsCollection
});
await db.init({
MONGO_DB,
overwriteMongoPath: null,
callback: checkAnyoneUser,
usernameField,
usersCollection,
projectsCollection,
annotationsCollection
});
app.db = db;
auth.init({ app, db, dirname, usernameField });
};
module.exports = {
authTokenMiddleware,
init,
getTokenEndPoint,
version,
...accessControl
};