-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
97 lines (91 loc) · 2.61 KB
/
index.js
File metadata and controls
97 lines (91 loc) · 2.61 KB
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
require('dotenv').config();
const session = require('express-session');
const { Keystone } = require('@keystonejs/keystone');
const { GraphQLApp } = require('@keystonejs/app-graphql');
const { AdminUIApp } = require('@keystonejs/app-admin-ui');
const { KnexAdapter: Adapter } = require('@keystonejs/adapter-knex');
const { PasswordAuthStrategy } = require('@keystonejs/auth-password');
const {
User,
Space,
LibrarySection,
Content,
Schedule,
Card,
Message,
MessageType,
Course,
Trainer,
Pricing,
Order,
FAQ,
Attachment,
Session,
Room,
} = require('./schema');
const { APP_NAME } = require('./constants');
const Auth = require('./auth');
const knexOptions = require('./knexfile');
const adapterConfig = { knexOptions };
const KnexSessionStore = require('connect-session-knex')(session);
const isProduction = process.env.NODE_ENV === 'production';
// Init keystone
const keystone = new Keystone({
name: APP_NAME,
cookieSecret: process.env.COOKIE_SECRET,
cookie: {
secure: isProduction,
},
adapter: new Adapter(adapterConfig),
sessionStore:
process.env.BUILD_STAGE !== undefined
? undefined
: new KnexSessionStore({
knex: require('knex')(knexOptions),
tablename: 'user_sessions', // optional. Defaults to 'sessions'
}),
});
// create our app entities
keystone.createList('User', User);
keystone.createList('Space', Space);
keystone.createList('LibrarySection', LibrarySection);
keystone.createList('Content', Content);
keystone.createList('Schedule', Schedule);
keystone.createList('Card', Card);
keystone.createList('Message', Message);
keystone.createList('MessageType', MessageType);
keystone.createList('Course', Course);
keystone.createList('Trainer', Trainer);
keystone.createList('Pricing', Pricing);
keystone.createList('Order', Order);
keystone.createList('FAQ', FAQ);
keystone.createList('Attachment', Attachment);
keystone.createList('Session', Session);
keystone.createList('Room', Room);
const authStrategy = keystone.createAuthStrategy({
type: PasswordAuthStrategy,
list: 'User',
});
const cors = {
origin: [
process.env.SERVER_URL,
// process.env.SERVER_URL.replace('https', 'http'), // don't support cors over http
],
credentials: true,
};
module.exports = {
keystone,
cors,
apps: [
new Auth(),
new GraphQLApp({ apollo: { cors } }),
new AdminUIApp({
name: 'NVC Learning Admin',
enableDefaultRoute: false,
authStrategy,
isAccessAllowed: ({ authentication: { item: user } }) =>
!!user && !!user.isAdmin && !user.disabled,
}),
],
configureExpress: (app) => app.set('trust proxy', 1),
};