-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.ts
55 lines (48 loc) · 1.54 KB
/
server.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
49
50
51
52
53
54
55
/* istanbul ignore file */
import * as Sentry from "@sentry/node";
import express, { Request, Response } from "express";
import next from "next";
import api from "./api";
import * as cardsUtils from "./utils/cards";
import { collectAllTags } from "./utils/tags";
const PORT = process.env.PORT || 8080;
const dev = process.env.NODE_ENV !== "production";
const app = next({ dev });
const handle = app.getRequestHandler();
Sentry.init({
dsn: "https://[email protected]/1325279",
beforeSend(event: Sentry.SentryEvent) {
if (!process.env.HEROKU) {
return null;
}
return event;
}
});
app
.prepare()
.then(() => cardsUtils.setupCardsStorage())
.then(() => collectAllTags())
.then(() => {
const server = express();
server.use(Sentry.Handlers.requestHandler() as express.RequestHandler);
// The error handler must be before any other error middleware
server.use(Sentry.Handlers.errorHandler() as express.ErrorRequestHandler);
server.use(api);
// The error handler must be before any other error middleware
server.use(Sentry.Handlers.errorHandler() as express.ErrorRequestHandler);
server.get("*", (request: Request, response: Response) =>
handle(request, response)
);
server.listen(PORT, (err: Error) => {
if (err) {
throw err;
}
/* tslint:disable no-console */
console.log(`Listen to the http://0.0.0.0:${PORT}`);
});
})
.catch((ex: any) => {
/* tslint:disable no-console */
console.error(ex.stack);
process.exit(1);
});