diff --git a/signer-service/src/index.js b/signer-service/src/index.js deleted file mode 100755 index 770e1df6..00000000 --- a/signer-service/src/index.js +++ /dev/null @@ -1,43 +0,0 @@ -const { port, env } = require('./config/vars'); -const logger = require('./config/logger'); -const app = require('./config/express'); -require('dotenv').config(); - -const { - FUNDING_SECRET, - PENDULUM_FUNDING_SEED, - MOONBEAM_EXECUTOR_PRIVATE_KEY, - CLIENT_DOMAIN_SECRET, -} = require('./constants/constants'); - -//stop the application if the funding secret key is not set -if (!FUNDING_SECRET) { - logger.error('FUNDING_SECRET not set in the environment variables'); - process.exit(1); -} - -// stop the application if the Pendulum funding seed is not set -if (!PENDULUM_FUNDING_SEED) { - logger.error('PENDULUM_FUNDING_SEED not set in the environment variables'); - process.exit(1); -} - -// stop the application if the Moonbeam executor private key is not set -if (!MOONBEAM_EXECUTOR_PRIVATE_KEY) { - logger.error('MOONBEAM_EXECUTOR_PRIVATE_KEY not set in the environment variables'); - process.exit(1); -} - -if (!CLIENT_DOMAIN_SECRET) { - logger.error('CLIENT_DOMAIN_SECRET not set in the environment variables'); - process.exit(1); -} - -// listen to requests -app.listen(port, () => logger.info(`server started on port ${port} (${env})`)); - -/** - * Exports express - * @public - */ -module.exports = app; diff --git a/signer-service/src/index.ts b/signer-service/src/index.ts new file mode 100755 index 00000000..d90c4868 --- /dev/null +++ b/signer-service/src/index.ts @@ -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;