-
Notifications
You must be signed in to change notification settings - Fork 0
/
getClientConfig.ts
30 lines (24 loc) · 1.17 KB
/
getClientConfig.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
import * as express from 'express';
import { validationResult } from 'express-validator';
import { ApiResponse } from '../apiResponse';
import allowedMethods from '../middlewares/allowedMethods';
import { ClientConfigResponse } from '../../types/endpoints';
const router = express.Router();
router.all('/', allowedMethods('GET'),
async (req, res) => {
const errors = validationResult(req);
if (!errors.isEmpty()) return new ApiResponse(res).validationError(errors);
const enableSocialLogin = process.env.ENABLE_SOCIAL_LOGIN === 'true';
const enableRecaptcha = process.env.ENABLE_RECAPTCHA === 'true';
const enableTenor = process.env.ENABLE_TENOR === 'true';
const result: ClientConfigResponse = {
googleClientId: enableSocialLogin && process.env.GOOGLE_CLIENT_ID,
facebookClientId: enableSocialLogin && process.env.GOOGLE_CLIENT_ID,
recaptchaSiteKey: enableRecaptcha && process.env.RECAPTCHA_SITE_KEY,
tenorApiKey: enableTenor && process.env.TENOR_API_KEY,
gaMeasurementId: enableTenor && process.env.GA_MEASUREMENT_ID
};
res.header('Cache-Control', `public, max-age=${12 * 60 * 60}, immutable`);
new ApiResponse(res).success(result);
});
export default router;