-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathkeystone.ts
93 lines (78 loc) · 2.56 KB
/
keystone.ts
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
// Welcome to Keystone!
//
// This file is what Keystone uses as the entry-point to your headless backend
//
// Keystone imports the default export of this file, expecting a Keystone configuration object
// you can find out more at https://keystonejs.com/docs/apis/config
require('dotenv').config()
import { config } from '@keystone-6/core';
import { extendGraphqlSchema, lists } from './src/keystone/schema';
import { nextAuthSessionStrategy } from './session';
// @ts-ignore
import type { Context } from '.keystone/types';
import { seedDatabase } from './src/keystone/seed/seedDatabase';
const DB_PROTOCOL = process.env.DB_PROTOCOL
const DB_USER = process.env.DB_USER
const DB_PASSWORD = process.env.DB_PASSWORD
const DB_DOMAIN = process.env.DB_DOMAIN
const DB_PORT = process.env.DB_PORT
const DB_COLLECTION = process.env.DB_COLLECTION
const DB_ENDPOINT = DB_PROTOCOL
+'://'
+DB_USER
+':'
+DB_PASSWORD
+'@'
+DB_DOMAIN
+':'
+DB_PORT
+'/'
+DB_COLLECTION
+'?connect_timeout=300'
// console.log({DB_ENDPOINT});
export default config({
db: {
provider: 'postgresql',
url: DB_ENDPOINT,
useMigrations: true,
onConnect: async (context: Context) => {
// TODO why argv doesn't work?
if (process.env.SEED_ME === 'true') {
// if (process.argv.includes('--seed-database')) {
await seedDatabase(context);
}
},
},
server: {
port: Number(process.env.BACKEND_PORT) || 3001,
cors: { origin: [process.env.NEXT_PUBLIC_FRONTEND_URL], credentials: true },
},
ui: {
// the following api routes are required for nextauth.js
publicPages: [
'/api/auth/csrf',
'/api/auth/signin',
'/api/auth/callback',
'/api/auth/session',
'/api/auth/providers',
'/api/auth/signout',
'/api/auth/error',
//! each provider will need a separate callback and signin page listed here
'/api/auth/signin/github',
'/api/auth/callback/github',
'/api/auth/signin/credentials',
'/api/auth/callback/credentials',
],
// adding page middleware ensures that users are redirected to the signin page if they are not signed in.
pageMiddleware: async ({ wasAccessAllowed }) => {
if (wasAccessAllowed) return;
return {
kind: 'redirect',
to: '/api/auth/signin',
};
},
},
lists,
extendGraphqlSchema,
session: nextAuthSessionStrategy,
})