-
Notifications
You must be signed in to change notification settings - Fork 3
/
env.js
43 lines (39 loc) · 1.02 KB
/
env.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
import fastifyEnv from "@fastify/env";
import fastifyPlugin from "fastify-plugin";
async function configPlugin(server, options, done) {
const schema = {
type: "object",
required: ["HTTP_PORT", "HTTP_HOST"],
properties: {
HTTP_PORT: {
type: "number",
default: 3000,
},
HTTP_HOST: {
type: "string",
default: "0.0.0.0",
},
DEBUG_LEVEL: {
type: "number",
default: 1000,
},
},
};
const configOptions = {
// decorate the Fastify server instance with `config` key
// such as `fastify.config('PORT')
confKey: "config",
// schema to validate
schema: schema,
// source for the configuration data
data: process.env,
// will read .env in root folder
dotenv: true,
// will remove the additional properties
// from the data object which creates an
// explicit schema
removeAdditional: true,
};
return fastifyEnv(server, configOptions, done);
}
export default fastifyPlugin(configPlugin);