2024-06-20 03:59:20 +00:00
|
|
|
import 'express-async-errors';
|
2024-01-16 09:36:35 +00:00
|
|
|
import 'reflect-metadata';
|
|
|
|
import debug from 'debug';
|
2024-01-17 04:32:06 +00:00
|
|
|
import fs from 'fs';
|
|
|
|
import path from 'path';
|
2024-01-16 09:36:35 +00:00
|
|
|
|
2024-01-30 14:20:53 +00:00
|
|
|
import { OAuthApp } from '@octokit/oauth-app';
|
|
|
|
|
2024-01-17 05:23:01 +00:00
|
|
|
import { Database } from './database';
|
2024-01-16 09:36:35 +00:00
|
|
|
import { createAndStartServer } from './server';
|
2024-01-17 04:32:06 +00:00
|
|
|
import { createResolvers } from './resolvers';
|
2024-01-16 09:36:35 +00:00
|
|
|
import { getConfig } from './utils';
|
2024-02-02 09:32:12 +00:00
|
|
|
import { Service } from './service';
|
2024-02-12 06:04:01 +00:00
|
|
|
import { Registry } from './registry';
|
2024-01-16 09:36:35 +00:00
|
|
|
|
|
|
|
const log = debug('snowball:server');
|
2024-02-12 06:04:01 +00:00
|
|
|
const OAUTH_CLIENT_TYPE = 'oauth-app';
|
2024-01-16 09:36:35 +00:00
|
|
|
|
|
|
|
export const main = async (): Promise<void> => {
|
2024-10-28 09:46:18 +00:00
|
|
|
const { server, database, gitHub, registryConfig } = await getConfig();
|
2024-01-17 05:23:01 +00:00
|
|
|
|
2024-01-30 14:20:53 +00:00
|
|
|
const app = new OAuthApp({
|
2024-02-12 06:04:01 +00:00
|
|
|
clientType: OAUTH_CLIENT_TYPE,
|
2024-02-15 11:54:57 +00:00
|
|
|
clientId: gitHub.oAuth.clientId,
|
2024-04-21 23:02:42 +00:00
|
|
|
clientSecret: gitHub.oAuth.clientSecret,
|
2024-01-30 14:20:53 +00:00
|
|
|
});
|
|
|
|
|
2024-10-23 15:36:19 +00:00
|
|
|
const db = new Database(database);
|
2024-02-08 09:29:19 +00:00
|
|
|
await db.init();
|
2024-02-12 06:04:01 +00:00
|
|
|
|
|
|
|
const registry = new Registry(registryConfig);
|
2024-02-22 05:45:17 +00:00
|
|
|
const service = new Service(
|
|
|
|
{ gitHubConfig: gitHub, registryConfig },
|
|
|
|
db,
|
|
|
|
app,
|
2024-04-21 23:02:42 +00:00
|
|
|
registry,
|
2024-02-22 05:45:17 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
const typeDefs = fs
|
|
|
|
.readFileSync(path.join(__dirname, 'schema.gql'))
|
|
|
|
.toString();
|
2024-02-08 09:29:19 +00:00
|
|
|
const resolvers = await createResolvers(service);
|
2024-01-17 05:23:01 +00:00
|
|
|
|
2024-02-15 11:54:57 +00:00
|
|
|
await createAndStartServer(server, typeDefs, resolvers, service);
|
2024-01-16 09:36:35 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
main()
|
|
|
|
.then(() => {
|
|
|
|
log('Starting server...');
|
|
|
|
})
|
|
|
|
.catch((err) => {
|
|
|
|
log(err);
|
|
|
|
});
|