snowballtools-base/packages/backend/src/index.ts

54 lines
1.3 KiB
TypeScript
Raw Normal View History

2024-06-20 03:59:20 +00:00
import 'express-async-errors';
import 'reflect-metadata';
import debug from 'debug';
import fs from 'fs';
import path from 'path';
import { OAuthApp } from '@octokit/oauth-app';
import { Database } from './database';
import { createAndStartServer } from './server';
import { createResolvers } from './resolvers';
import { getConfig } from './utils';
import { Service } from './service';
import { Registry } from './registry';
const log = debug('snowball:server');
const OAUTH_CLIENT_TYPE = 'oauth-app';
export const main = async (): Promise<void> => {
2024-04-21 23:02:42 +00:00
const { server, database, gitHub, registryConfig, misc } = await getConfig();
const app = new OAuthApp({
clientType: OAUTH_CLIENT_TYPE,
clientId: gitHub.oAuth.clientId,
2024-04-21 23:02:42 +00:00
clientSecret: gitHub.oAuth.clientSecret,
});
const db = new Database(database, misc);
await db.init();
const registry = new Registry(registryConfig);
const service = new Service(
{ gitHubConfig: gitHub, registryConfig },
db,
app,
2024-04-21 23:02:42 +00:00
registry,
);
const typeDefs = fs
.readFileSync(path.join(__dirname, 'schema.gql'))
.toString();
const resolvers = await createResolvers(service);
await createAndStartServer(server, typeDefs, resolvers, service);
};
main()
.then(() => {
log('Starting server...');
})
.catch((err) => {
log(err);
});