You can not select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			
		
			
				
					21 lines
				
				421 B
			
		
		
			
		
	
	
					21 lines
				
				421 B
			| 
								 
											3 years ago
										 
									 | 
							
								'use strict'
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								const fp = require('fastify-plugin')
							 | 
						||
| 
								 | 
							
								const envSchema = require('env-schema')
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								function loadAndValidateEnvironment (fastify, opts, done) {
							 | 
						||
| 
								 | 
							
								  try {
							 | 
						||
| 
								 | 
							
								    const config = envSchema(opts)
							 | 
						||
| 
								 | 
							
								    const confKey = opts.confKey || 'config'
							 | 
						||
| 
								 | 
							
								    fastify.decorate(confKey, config)
							 | 
						||
| 
								 | 
							
								    done()
							 | 
						||
| 
								 | 
							
								  } catch (err) {
							 | 
						||
| 
								 | 
							
								    done(err)
							 | 
						||
| 
								 | 
							
								  }
							 | 
						||
| 
								 | 
							
								}
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								module.exports = fp(loadAndValidateEnvironment, {
							 | 
						||
| 
								 | 
							
								  fastify: '3.x',
							 | 
						||
| 
								 | 
							
								  name: 'fastify-env'
							 | 
						||
| 
								 | 
							
								})
							 |