-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.configuration.ts
143 lines (132 loc) · 3.46 KB
/
app.configuration.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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
import secrets, { EmailConfig } from 'secrets';
export default ((): AppConfig => {
const shared = (frontUrl: string) => ({
frontUrl,
serverUrl: 'https://aqueous-caverns-91110.herokuapp.com',
nodeEnv: process.env.APP_ENV as 'dev' | 'prod',
stripe: {
apiKey: secrets.stripe.apiKey,
successPageUrl: `${frontUrl}/order/thank-you`,
cancelPageUrl: `${frontUrl}/order/error`,
// IMPORTANT: Keep track of all Stripe integrations' api versions (including webhooks)
apiVersion: '2020-08-27' as const,
webhook: {
// Default set in @golevelup/nestjs-stripe library
path: 'stripe/webhook',
secret: secrets.stripe.webhookSecret,
},
},
cookie: {
authIndicatorName: 'auth',
tokenName: 'token',
tokenExpiration: '7d',
},
auth: {
tokenKey: secrets.authTokenKey,
verificationTokenExpiration: '30m',
authTokenExpiration: '7d',
successRedirectUrl: `${frontUrl}/auth/success`,
},
mongo: { connectionString: secrets.mongoConnectionString },
email: secrets.email,
serviceFee: {
stripeProductId: 'prod_KhDFjew4BDycpd',
stripePriceId: 'price_1K1oojFkgohp7fDw5cKL2wiy',
loclyCutPercent: 20,
},
rewards: {
referralUsd: 5,
refereeUsd: 5,
codeLength: 6,
},
host: {
payoutDelayDays: 19,
},
});
if (process.env.APP_ENV === 'dev') {
const sharedConfig = shared('http://localhost:3000');
return {
...sharedConfig,
mongo: {
...sharedConfig.mongo,
dbName: 'dev',
},
cookie: {
...sharedConfig.cookie,
cors: { secure: false, sameSite: 'lax' } as const,
},
};
}
if (process.env.APP_ENV === 'prod') {
const sharedConfig = shared('https://loclynew.netlify.app');
return {
...sharedConfig,
mongo: {
...sharedConfig.mongo,
dbName: 'prod',
},
cookie: {
...sharedConfig.cookie,
// Only 'SameSite=None; Secure' cookies are forwarded in third-party requests,
// which is necessary in production to allow the front-end on domain X (see main.ts :: enableCors config)
// to send request to server on domain Y:
// https://stackoverflow.com/a/46412839/6539857
// https://digiday.com/media/what-is-chrome-samesite/
cors: { secure: true, sameSite: 'none' } as const,
},
};
}
throw new Error('No ENV passed');
})();
export type StripeConfig = {
apiKey: string;
apiVersion: '2020-08-27';
webhook: {
secret: string;
path: string;
};
successPageUrl: string;
cancelPageUrl: string;
};
export type MongoConfig = {
connectionString: string;
dbName: string;
};
export type CookieConfig = {
authIndicatorName: string;
tokenName: string;
tokenExpiration: string;
cors: {
secure: boolean;
sameSite: 'strict' | 'lax' | 'none';
};
};
export type AuthConfig = {
tokenKey: string;
verificationTokenExpiration: string;
authTokenExpiration: string;
successRedirectUrl: string;
};
export type AppConfig = {
frontUrl: string;
serverUrl: string;
nodeEnv: 'dev' | 'prod';
stripe: StripeConfig;
mongo: MongoConfig;
cookie: CookieConfig;
auth: AuthConfig;
email: EmailConfig;
serviceFee: {
stripeProductId: string;
stripePriceId: string;
loclyCutPercent: number;
};
rewards: {
referralUsd: number;
refereeUsd: number;
codeLength: number;
};
host: {
payoutDelayDays: number;
};
};