-
Notifications
You must be signed in to change notification settings - Fork 115
/
server.ts
58 lines (52 loc) · 1.77 KB
/
server.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
import { gqlSdk } from '@/utils';
import { ENV } from '@/utils/env';
import { logger, LOG_LEVEL } from './logger';
export const start = async () => {
logger.info(`Log level: ${LOG_LEVEL}`);
/**
* Async imports allow to dynamically import the required modules,
* and therefore only import modules that are required, when they are required.
* It decreases the loading time on startup.
* This distinction can make a difference if using hasura-auth to only apply migrations/metadata,
* or to skip migrations/metadata on startup.
*/
// if (ENV.AUTH_SKIP_INIT) {
// logger.info(`Skipping migrations and metadata`);
// } else {
const { waitForHasura } = await import('@/utils');
const { applyMigrations } = await import('./migrations');
const { applyMetadata } = await import('./metadata');
// wait for hasura to be ready
await waitForHasura();
// apply migrations and metadata
await applyMigrations();
await applyMetadata();
// }
// * Insert missing default allowed roles into the database
const { insertAuthRoles } = await gqlSdk.upsertRoles({
roles: [
...new Set([
...ENV.AUTH_USER_DEFAULT_ALLOWED_ROLES,
ENV.AUTH_USER_DEFAULT_ROLE,
]),
].map((role) => ({ role })),
});
if (insertAuthRoles?.affected_rows) {
logger.info(
`Inserted ${
insertAuthRoles.affected_rows
} roles: ${insertAuthRoles.returning.map(({ role }) => role).join(', ')}`
);
}
// if (ENV.AUTH_SKIP_SERVE) {
// logger.info(
// `AUTH_SKIP_SERVE has been set to true, therefore Hasura-Auth won't start`
// );
// } else {
await import('./env-vars-check');
const { app } = await import('./app');
app.listen(ENV.AUTH_PORT, () => {
logger.info(`Running on port ${ENV.AUTH_PORT}`);
});
// }
};