-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
77 lines (70 loc) · 2.64 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
77
require('dotenv-safe').config();
const { Keystone } = require('@keystonejs/keystone');
const { PasswordAuthStrategy } = require('@keystonejs/auth-password');
const { GraphQLApp } = require('@keystonejs/app-graphql');
const { AdminUIApp } = require('@keystonejs/app-admin-ui');
const { NextApp } = require('@keystonejs/app-next');
const { MongooseAdapter: Adapter } = require('@keystonejs/adapter-mongoose');
const expressSession = require('express-session');
const MongoStore = require('connect-mongo')(expressSession);
const initialiseData = require('./initial-data');
const CheckAuthentication = require('./routes/authentication');
const S3Upload = require('./routes/upload');
const Duplicate = require('./routes/duplicate');
const Download = require('./routes/download');
const ResetPassword = require('./routes/reset');
const ChangePassword = require('./routes/password');
const UserSchema = require('./lists/User');
const ProjectSchema = require('./lists/Project');
const SlideSchema = require('./lists/Slide');
const ImageSchema = require('./lists/Image');
const TagSchema = require('./lists/Tag');
const LayerSchema = require('./lists/Layer');
const BasemapSchema = require('./lists/Basemap');
const AnnotationSchema = require('./lists/Annotation');
const PROJECT_NAME = 'imagineRio Narratives';
const adapterConfig = { mongoUri: `${process.env.MONGO_URI}${process.env.MONGO_DB}` };
const keystone = new Keystone({
adapter: new Adapter(adapterConfig),
onConnect: process.env.CREATE_TABLES !== 'true' && initialiseData,
cookieSecret: process.env.COOKIE_SECRET,
sessionStore: new MongoStore({ url: `${process.env.MONGO_URI}${process.env.MONGO_DB}` }),
});
keystone.createList('User', UserSchema);
const authStrategy = keystone.createAuthStrategy({
type: PasswordAuthStrategy,
list: 'User',
});
keystone.createList('Slide', SlideSchema);
keystone.createList('Image', ImageSchema);
keystone.createList('Project', ProjectSchema);
keystone.createList('Tag', TagSchema);
keystone.createList('Layer', LayerSchema);
keystone.createList('Basemap', BasemapSchema);
keystone.createList('Annotation', AnnotationSchema);
module.exports = {
keystone,
apps: [
new GraphQLApp({
apollo: {
introspection: true,
},
}),
new AdminUIApp({
name: PROJECT_NAME,
enableDefaultRoute: false,
authStrategy,
isAccessAllowed: ({ authentication: { item: user } }) => !!user && !!user.isAdmin,
}),
new CheckAuthentication(),
new S3Upload(),
new Duplicate(),
new Download(),
new ResetPassword(),
new ChangePassword(),
new NextApp({ dir: 'src' }),
],
configureExpress: app => {
app.set('trust proxy', true);
},
};