forked from KuroZen/r34-json-api
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.ts
48 lines (39 loc) · 1.15 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
42
43
44
45
46
47
48
// env
import dotenv from "dotenv";
dotenv.config();
// packages
import compression from "compression";
import cors from "cors";
import express from "express";
import * as Sentry from "@sentry/node";
import * as Tracing from "@sentry/tracing";
import ua from "universal-analytics";
import version1 from "./src/v1/version1";
import { version2 } from "./src/v2/version2";
// environment
const { PORT, TRACKING_ID, npm_package_version } = process.env;
// app
const app = express();
Sentry.init({
dsn: "https://[email protected]/5907391",
integrations: [
new Sentry.Integrations.Http({ tracing: true }),
new Tracing.Integrations.Express({ app }),
],
release: npm_package_version,
});
// middleware
app.use(Sentry.Handlers.requestHandler());
app.use(Sentry.Handlers.tracingHandler());
app.use(cors());
app.use(compression());
TRACKING_ID && app.use(ua.middleware(TRACKING_ID, { cookieName: "_ga" }));
// versions
app.use("/", version1);
app.use("/v1", version1);
app.use("/v2", version2);
app.use(Sentry.Handlers.errorHandler());
// start
app.listen(PORT, () => {
console.log(`App listening on port ${PORT}.`);
});