-
-
Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathindex.js
More file actions
30 lines (25 loc) · 677 Bytes
/
index.js
File metadata and controls
30 lines (25 loc) · 677 Bytes
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
'use strict'
const fp = require('fastify-plugin')
const envSchema = require('env-schema')
function fastifyEnv (fastify, opts, done) {
try {
const config = envSchema(opts)
const confKey = opts.confKey || 'config'
fastify.decorate(confKey, config)
if (!fastify.hasDecorator('getEnvs')) {
fastify.decorate('getEnvs', () => config)
}
if (!fastify.hasRequestDecorator('getEnvs')) {
fastify.decorateRequest('getEnvs', () => config)
}
done()
} catch (err) {
done(err)
}
}
module.exports = fp(fastifyEnv, {
fastify: '5.x',
name: '@fastify/env'
})
module.exports.default = fastifyEnv
module.exports.fastifyEnv = fastifyEnv