mirror of
https://github.com/monkeytypegame/monkeytype.git
synced 2024-11-10 17:04:49 +08:00
45 lines
1.4 KiB
TypeScript
45 lines
1.4 KiB
TypeScript
import "dotenv/config";
|
|
import admin, { ServiceAccount } from "firebase-admin";
|
|
// @ts-ignore
|
|
import serviceAccount from "./credentials/serviceAccountKey.json"; // eslint-disable-line require-path-exists/exists
|
|
import db from "./init/db";
|
|
import jobs from "./jobs";
|
|
import ConfigurationClient from "./init/configuration";
|
|
import app from "./app";
|
|
import { Server } from "http";
|
|
|
|
async function bootServer(port: number): Promise<Server> {
|
|
try {
|
|
console.log(`Connecting to database ${process.env.DB_NAME}...`);
|
|
await db.connect();
|
|
console.log("Connected to database");
|
|
|
|
console.log("Initializing Firebase app instance...");
|
|
admin.initializeApp({
|
|
credential: admin.credential.cert(
|
|
serviceAccount as unknown as ServiceAccount
|
|
),
|
|
});
|
|
console.log("Firebase app initialized");
|
|
|
|
console.log("Fetching live configuration...");
|
|
await ConfigurationClient.getLiveConfiguration();
|
|
console.log("Live configuration fetched");
|
|
|
|
console.log("Starting cron jobs...");
|
|
jobs.forEach((job) => job.start());
|
|
console.log("Cron jobs started");
|
|
} catch (error) {
|
|
console.error("Failed to boot server");
|
|
console.error(error);
|
|
return process.exit(1);
|
|
}
|
|
|
|
return app.listen(PORT, () => {
|
|
console.log(`API server listening on port ${port}`);
|
|
});
|
|
}
|
|
|
|
const PORT = parseInt(process.env.PORT) || 5005;
|
|
|
|
bootServer(PORT);
|