-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathindex.ts
More file actions
66 lines (53 loc) · 2.15 KB
/
Copy pathindex.ts
File metadata and controls
66 lines (53 loc) · 2.15 KB
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import "./instrument.js";
import express, { type Express } from "express";
import "reflect-metadata";
import cors from "cors";
import { getRequiredEnvVar } from "./utils/envVars.js";
import { yoga } from "./client/graphql.js";
import swaggerUi from "swagger-ui-express";
import swaggerJson from "./__generated__/swagger.json" assert { type: "json" };
import { RegisterRoutes } from "./__generated__/routes/routes.js";
import * as Sentry from "@sentry/node";
import SignatureRequestProcessorCron from "./cron/SignatureRequestProcessing.js";
import OrderInvalidationCronjob from "./cron/OrderInvalidation.js";
import { container } from "tsyringe";
import { ENABLE_CRON_JOBS } from "./utils/constants.js";
// @ts-expect-error BigInt is not supported by JSON
BigInt.prototype.toJSON = function () {
const int = Number.parseInt(this.toString());
return int ?? this.toString();
};
// @ts-expect-error BigInt is not supported by JSON
BigInt.prototype.fromJSON = function () {
return BigInt(this.toString());
};
const PORT = getRequiredEnvVar("PORT");
const app: Express = express();
app.use(express.urlencoded({ extended: true, limit: "10mb" }));
app.use(express.json({ limit: "10mb" }));
app.use(cors());
// Bind GraphQL Yoga to the graphql endpoint to avoid rendering the playground on any path
app.use(yoga.graphqlEndpoint, yoga);
app.use("/spec", swaggerUi.serve, swaggerUi.setup(swaggerJson));
app.get("/swagger.json", (req, res) => {
res.setHeader("Content-Type", "application/json");
res.send(swaggerJson);
});
RegisterRoutes(app);
// The error handler must be registered before any other error middleware and after all controllers
Sentry.setupExpressErrorHandler(app);
// Start Safe signature request processing cron job
if (ENABLE_CRON_JOBS) {
console.log("🚀 Starting cron jobs");
SignatureRequestProcessorCron.start();
const cronJob = container.resolve(OrderInvalidationCronjob);
cronJob.start();
} else {
console.log("🚨 Cron jobs are disabled");
}
app.listen(PORT, () => {
console.log(
`🕸️ Running a GraphQL API server at http://localhost:${PORT}/v2/graphql`,
);
console.log(`🚀 Running Swagger docs at http://localhost:${PORT}/spec`);
});