-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathmain.ts
More file actions
58 lines (51 loc) · 1.84 KB
/
main.ts
File metadata and controls
58 lines (51 loc) · 1.84 KB
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
import cors from 'cors';
import express from 'express';
import helmet from 'helmet';
import { getEnv } from './env.js';
import getLogger from './logger.js';
import initApiPlaygroundRoutes from './packages/api-playground/api-playground.js';
import initAuthRoutes from './packages/auth/routes.js';
import { DbMerlin } from './packages/db/db.js';
import initFileRoutes from './packages/files/files.js';
import initHasuraRoutes from './packages/hasura/hasura-events.js';
import initHealthRoutes from './packages/health/health.js';
import initPlanRoutes from './packages/plan/plan.js';
import initSwaggerRoutes from './packages/swagger/swagger.js';
import cookieParser from 'cookie-parser';
import { AuthAdapter } from './types/auth.js';
import { NoAuthAdapter } from './packages/auth/adapters/NoAuthAdapter.js';
import { CAMAuthAdapter } from './packages/auth/adapters/CAMAuthAdapter.js';
import { validateGroupRoleMappings } from './packages/auth/functions.js';
async function main(): Promise<void> {
const logger = getLogger('main');
const { PORT, AUTH_TYPE } = getEnv();
const app = express();
app.use(helmet({ contentSecurityPolicy: false, crossOriginEmbedderPolicy: false }));
app.use(cors());
app.use(express.json());
app.use(cookieParser());
await DbMerlin.init();
let authHandler: AuthAdapter;
switch (AUTH_TYPE) {
case 'none':
authHandler = NoAuthAdapter;
break;
case 'cam':
validateGroupRoleMappings();
authHandler = CAMAuthAdapter;
break;
default:
throw new Error(`invalid auth type env var: ${AUTH_TYPE}`);
}
initApiPlaygroundRoutes(app);
initAuthRoutes(app, authHandler);
initFileRoutes(app);
initHealthRoutes(app);
initHasuraRoutes(app);
initPlanRoutes(app);
initSwaggerRoutes(app);
app.listen(PORT, () => {
logger.info(`🚀 AERIE-GATEWAY listening on ${PORT}`);
});
}
main();