This repository has been archived by the owner on Jun 23, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
75 lines (66 loc) · 2.25 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
require("dotenv").config()
const expressSession = require("express-session")
const redis = require("redis")
let RedisStore = require("connect-redis")(expressSession)
let redisClient = redis.createClient()
let MongoStore = require("connect-mongo")(expressSession)
const { Keystone } = require("@keystonejs/keystone")
const { GraphQLApp } = require("@keystonejs/app-graphql")
const { AdminUIApp } = require("@keystonejs/app-admin-ui")
const { NuxtApp } = require("@keystonejs/app-nuxt")
const { MongooseAdapter: Adapter } = require("@keystonejs/adapter-mongoose")
const PageSchema = require("./lists/Page")
const UserSchema = require("./lists/User")
const PostSchema = require("./lists/Post")
const TagSchema = require("./lists/Tag")
const CategorySchema = require("./lists/Category")
const CommentSchema = require("./lists/Comment")
const DefaultAuthStrategy = require("./auth/Default.js")
const UserSeeder = require("./lists/seed/User")
const nuxtConfig = require("./config/nuxtConfig")
const adapterConfig = {
mongoUri: "mongodb://" + process.env.DB_HOST + "/" + process.env.DB_NAME,
url: "mongodb://" + process.env.DB_HOST + "/" + process.env.DB_NAME
}
const keystone = new Keystone({
name: process.env.APP_NAME,
cookieSecret: process.env.COOKIE_SECRET,
sessionStore:
process.env.SESSION_CLIENT === "redis"
? new RedisStore({ client: redisClient })
: new MongoStore(adapterConfig),
adapter: new Adapter(adapterConfig),
queryLimits: {
maxTotalResults: 1000
},
onConnect: async keystone => {
try {
await keystone.createItems(UserSeeder)
} catch (e) {
console.log("can not seed user a second time")
}
}
})
keystone.createList("Page", PageSchema)
keystone.createList("User", UserSchema)
keystone.createList("Post", PostSchema)
keystone.createList("Tag", TagSchema)
keystone.createList("Category", CategorySchema)
if (
process.env.POSTS_ENABLE_COMMENTS !== "" &&
process.env.POSTS_ENABLE_COMMENTS !== "false"
) {
keystone.createList("Comment", CommentSchema)
}
const authStrategy = keystone.createAuthStrategy(DefaultAuthStrategy)
module.exports = {
keystone,
apps: [
new GraphQLApp(),
new AdminUIApp({ authStrategy }),
new NuxtApp(nuxtConfig)
],
configureExpress: app => {
app.set("trust proxy", true)
}
}