-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
51 lines (44 loc) · 1.61 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
if (process.env.NODE_ENV !== 'production') require('dotenv').config();
const { Keystone } = require('@keystonejs/keystone');
const { PasswordAuthStrategy } = require('@keystonejs/auth-password');
const { MongooseAdapter } = require('@keystonejs/adapter-mongoose');
const { GraphQLApp } = require('@keystonejs/app-graphql');
const { AdminUIApp } = require('@keystonejs/app-admin-ui');
const { NextApp } = require('@keystonejs/app-next');
const { StaticApp } = require('@keystonejs/app-static');
const { staticRoute, staticPath, distDir } = require('./keystone/config');
const { User, Article } = require('./keystone/models/_schema');
const keystone = new Keystone({
name: '',
adapter: new MongooseAdapter({ mongoUri: process.env.MONGO_URI_TEMP }),
onConnect: async () => {
// TODO: This is only for demo purposes and should not be used in production
const users = await keystone.lists.User.adapter.findAll();
if (!users.length) {
const initialData = require('./keystone/seed');
await keystone.createItems(initialData);
}
},
});
keystone.createList('User', User);
keystone.createList('Article', Article);
const authStrategy = keystone.createAuthStrategy({
type: PasswordAuthStrategy,
list: 'User',
});
const adminApp = new AdminUIApp({
adminPath: '/admin',
hooks: require.resolve('./keystone/admin-ui/'),
authStrategy,
isAccessAllowed: ({ authentication: { item: user } }) => !!user && !!user.isAdmin,
});
module.exports = {
keystone,
apps: [
new GraphQLApp(),
new StaticApp({ path: staticRoute, src: staticPath }),
adminApp,
new NextApp({ dir: 'src' }),
],
distDir,
};