forked from HeimLabs/coinbase-myusdc-backend
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.ts
41 lines (34 loc) · 1.06 KB
/
index.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
import "dotenv/config";
import middlewares from "./middlewares";
import router from "./routes";
import express from "express";
import { coinbase, database } from "./services";
import { ServerSigner } from "@coinbase/coinbase-sdk";
const start = async () => {
let app = express();
app = middlewares(app);
app.use(router);
await database.connectToDatabase();
await coinbase.setupFaucet();
app.listen(process.env.PORT || 5000, async () => {
try {
console.log(`🚀 Server running on port ${process.env.PORT || 5000}`);
if (await ServerSigner.getDefault())
console.log("✅ Coinbase ServerSigner connected!");
} catch (error) {
console.log("❌ Coinbase ServerSigner failed to connect!");
await gracefulShutdown();
}
});
}
async function gracefulShutdown() {
try {
process.exit(0);
} catch (error) {
console.error(error);
process.exit(1);
}
}
process.on("SIGINT", gracefulShutdown);
process.on("SIGTERM", gracefulShutdown);
start();