-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.ts
38 lines (32 loc) · 808 Bytes
/
app.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
import "source-map-support/register";
import express, { type ErrorRequestHandler } from "express";
import { pinoHttp } from "pino-http";
import pino from "pino";
const app = express();
app.use(
pinoHttp({
logger: pino({
transport: {
target: "pino-pretty",
options: {
colorize: true,
singleLine: true,
},
},
}),
}),
);
app.get("/", (_req, _res) => {
throw new Error("not happy");
});
const errHandler: ErrorRequestHandler = (err, _req, res, _next) => {
return res
.status(500)
.json({ error: { name: err.name, message: err.message, stack: err.stack } })
.end();
};
app.use(errHandler);
const port = process.env.PORT ? Number(process.env.PORT) : 8080;
app.listen(port, () => {
console.log(`listening on ${port}`);
});