-
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.
- Loading branch information
1 parent
7b213eb
commit 6d57274
Showing
2 changed files
with
44 additions
and
43 deletions.
There are no files selected for viewing
This file was deleted.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import dotenv from 'dotenv'; | ||
|
||
import { config } from './config/vars'; | ||
import logger from './config/logger'; | ||
import app from './config/express'; | ||
import { | ||
FUNDING_SECRET, | ||
PENDULUM_FUNDING_SEED, | ||
MOONBEAM_EXECUTOR_PRIVATE_KEY, | ||
CLIENT_DOMAIN_SECRET, | ||
} from './constants/constants'; | ||
|
||
const { port, env } = config; | ||
|
||
dotenv.config(); | ||
|
||
// Consider grouping all environment checks into a single function | ||
const validateRequiredEnvVars = () => { | ||
const requiredVars = { | ||
FUNDING_SECRET, | ||
PENDULUM_FUNDING_SEED, | ||
MOONBEAM_EXECUTOR_PRIVATE_KEY, | ||
CLIENT_DOMAIN_SECRET, | ||
}; | ||
|
||
for (const [key, value] of Object.entries(requiredVars)) { | ||
if (!value) { | ||
logger.error(`${key} not set in the environment variables`); | ||
process.exit(1); | ||
} | ||
} | ||
}; | ||
|
||
// Validate environment variables before starting the server | ||
validateRequiredEnvVars(); | ||
|
||
// listen to requests | ||
app.listen(port, () => logger.info(`server started on port ${port} (${env})`)); | ||
|
||
/** | ||
* Exports express | ||
* @public | ||
*/ | ||
export default app; |