-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsettings.ts
41 lines (38 loc) · 1.18 KB
/
settings.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
import send from "@polka/send-type";
import pkg from "./package.json";
import { ISettings } from "./src/interfaces/ISettings";
import { ServerRequest, ServerResponse } from "polka";
process.env.NODE_ENV = process.env.NODE_ENV || "development";
const env = process.env.NODE_ENV.startsWith("dev") ? "development" : "production";
const settings: ISettings = {
version: pkg.version,
env,
polka: {
onError: (err: Error, _req: ServerRequest, res: ServerResponse) => {
console.error(err);
send(res, 500, {
statusCode: 500,
statusMessage: "Internal Server Error",
data: {
message: typeof err === "string" ? err : err.toString()
}
});
},
onNoMatch: (_req: ServerRequest, res: ServerResponse) => {
send(res, 404, {
statusCode: 404,
statusMessage: "Not Found",
data: {
message: "Route does not exist"
}
});
}
},
api: {
headers: {
"x-powered-by": "polka",
env
}
}
};
export default settings;