-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added validation and fixed some potential bugs
- Loading branch information
Showing
7 changed files
with
151 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
.env |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import dotenv from 'dotenv'; | ||
import Joi from 'joi'; | ||
|
||
dotenv.config(); | ||
|
||
// Define the schema for validation | ||
const envVarsSchema = Joi.object({ | ||
PORT: Joi.number().default(3000), | ||
ELAWAY_USER: Joi.string().email().required(), | ||
ELAWAY_CLIENT_ID: Joi.string().default('1'), | ||
ELAWAY_CLIENT_SECRET: Joi.string().required(), | ||
ELAWAY_PASSWORD: Joi.string().required(), | ||
POLLING_INTERVAL: Joi.number().default(60000), | ||
CLIENT_ID: Joi.string().required() | ||
}).unknown(); | ||
|
||
// Validate environment variables | ||
const { value: envVars, error } = envVarsSchema | ||
.prefs({ errors: { label: 'key' } }) | ||
.validate(process.env); | ||
|
||
if (error) { | ||
throw new Error(`Config validation error: ${error.message}`); | ||
} | ||
|
||
// Export the validated config | ||
const config = { | ||
port: envVars.PORT, | ||
elawayUser: envVars.ELAWAY_USER, | ||
elawayPassword: envVars.ELAWAY_PASSWORD, | ||
elawayClientId: envVars.ELAWAY_CLIENT_ID, | ||
elawayClientSecret: envVars.ELAWAY_CLIENT_SECRET, | ||
pollingInterval: envVars.POLLING_INTERVAL, | ||
clientId: envVars.CLIENT_ID, | ||
}; | ||
|
||
export default config; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters