-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathserver.js
131 lines (98 loc) · 3.43 KB
/
server.js
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
import * as Sentry from "@sentry/node";
import { ProfilingIntegration } from "@sentry/profiling-node";
import * as Tracing from "@sentry/tracing";
import https from "@small-tech/https";
import createExpress from "express";
import helmet from "helmet";
import {
bodyParser,
errorHandler,
ipCheckMiddleware,
logActivities,
logRequestMiddleware,
notFoundHandler,
requestLogger
} from "toot-sweet/middleware";
import { apiRouter, nodeinfoRouter, peopleRouter, wellKnownRouter } from "toot-sweet/routes";
import {loadConfiguration} from "./lib/config.js";
import { Grouper } from "./lib/Grouper.js";
import { Link } from "./lib/Link.js";
import log from "./lib/logger.js";
import { PeopleConnector } from "./lib/PeopleConnector.js";
const app = createExpress();
const config = loadConfiguration()
const options = {
domains: [config.siteHost],
settingsPath: "data",
};
Sentry.init({
dsn: "https://[email protected]/4504277664661504",
// Set tracesSampleRate to 1.0 to capture 100%
// of transactions for performance monitoring.
// We recommend adjusting this value in production
tracesSampleRate: 1.0,
profilesSampleRate: 1.0, // Profiling sample rate is relative to tracesSampleRate
integrations: [
// enable HTTP calls tracing
new Sentry.Integrations.Http({ tracing: true }),
// enable Express.js middleware tracing
new Tracing.Integrations.Express({ app }),
// Add profiling integration to list of integrations
new ProfilingIntegration(),
],
});
// RequestHandler creates a separate execution context using domains, so that every
// transaction/span/breadcrumb is attached to its own Hub instance
app.use(Sentry.Handlers.requestHandler());
// TracingHandler creates a trace for every incoming request
app.use(Sentry.Handlers.tracingHandler());
app.disable("x-powered-by");
app.use(ipCheckMiddleware);
app.use(helmet());
app.use(logRequestMiddleware);
app.use(bodyParser);
app.use(logActivities);
app.use("/api", apiRouter);
app.use(requestLogger);
app.use("/.well-known", wellKnownRouter);
app.use("/nodeinfo", nodeinfoRouter);
app.use("/people", peopleRouter);
// This needs to redirect to /people
app.use("/users", peopleRouter);
// static files
app.use(createExpress.static("./build"));
// custom 404
app.use(notFoundHandler);
// custom error handler
app.use(errorHandler);
try {
const grouper = Grouper.getGrouper();
PeopleConnector.getPeopleConnector(config).addPerson("drazi");
PeopleConnector.getPeopleConnector(config).addPerson("self");
grouper.createGroup("activityStreamsInbound");
grouper.createGroup("actorsSeen");
grouper.createGroup("remoteActors");
const server = https.createServer(options, app);
grouper.createGroup("localHosts");
config.localHosts.forEach((/** @type {string} */ entry) => {
const host = new Link(entry, entry);
host.id = entry;
grouper.addToGroup("localHosts", host);
});
grouper.createGroup("blockedIPs");
config.blockList.forEach((/** @type {string} */ entry) => {
const host = new Link(entry, entry);
host.id = entry;
grouper.addToGroup("blockedIPs", host);
});
server.listen(443, () => {
log.info(Object({ server: { status: "listening" } }));
});
server.on("error", (err) => {
log.error(Object({ server: { status: "errored", reason: String(err) } }));
});
} catch (error) {
console.error(error);
log.error({ reason: `Fatal error!: ${String(error) }` });
process.exit(-1);
}