mirror of
https://github.com/brendan-ch/project-inter-server.git
synced 2026-04-17 07:50:31 +00:00
56 lines
1.9 KiB
TypeScript
56 lines
1.9 KiB
TypeScript
import { readFileSync } from "fs";
|
|
import { ApolloServer } from "@apollo/server";
|
|
import { startStandaloneServer } from "@apollo/server/standalone";
|
|
import { MergedResolvers } from "./MergedResolvers";
|
|
import { ServerContext } from "./ServerContext";
|
|
import { UnoptimizedInMemoryRepository } from "./repositories/UnoptimizedInMemoryRepository";
|
|
import { TimedApiBasedRepositoryLoader } from "./loaders/TimedApiBasedRepositoryLoader";
|
|
import { ETANotificationScheduler } from "./notifications/schedulers/ETANotificationScheduler";
|
|
import { configDotenv } from "dotenv";
|
|
import { loadTestData } from "./loaders/loadTestData";
|
|
import { AppleNotificationSender } from "./notifications/senders/AppleNotificationSender";
|
|
|
|
configDotenv();
|
|
|
|
const typeDefs = readFileSync("./schema.graphqls", "utf8");
|
|
|
|
async function main() {
|
|
const server = new ApolloServer<ServerContext>({
|
|
typeDefs,
|
|
resolvers: MergedResolvers,
|
|
introspection: process.env.NODE_ENV !== "production",
|
|
});
|
|
|
|
const repository = new UnoptimizedInMemoryRepository();
|
|
let notificationService: ETANotificationScheduler;
|
|
if (process.argv.length > 2 && process.argv[2] == "integration-testing") {
|
|
console.log("Using integration testing setup")
|
|
await loadTestData(repository);
|
|
const appleNotificationSender = new AppleNotificationSender(false);
|
|
notificationService = new ETANotificationScheduler(repository, appleNotificationSender);
|
|
} else {
|
|
const repositoryDataUpdater = new TimedApiBasedRepositoryLoader(
|
|
repository
|
|
);
|
|
await repositoryDataUpdater.start();
|
|
notificationService = new ETANotificationScheduler(repository);
|
|
}
|
|
|
|
const { url } = await startStandaloneServer(server, {
|
|
listen: {
|
|
port: process.env.PORT ? parseInt(process.env.PORT) : 4000,
|
|
},
|
|
context: async ({ req, res }) => {
|
|
return {
|
|
repository,
|
|
notificationService,
|
|
}
|
|
},
|
|
});
|
|
|
|
|
|
console.log(`Server ready at: ${url}`);
|
|
}
|
|
|
|
main();
|