build: check all relevant environment variables are set on start up
This commit is contained in:
parent
1d960c6854
commit
982514c727
3 changed files with 20 additions and 1 deletions
|
@ -57,7 +57,7 @@
|
|||
<div class="container">
|
||||
<h2>Get Started</h2>
|
||||
<p>Ready to take the next step in your IT career? Apply today!</p>
|
||||
<form id="applicationForm">
|
||||
<form id="applicationForm" method="post" action="https://mailer.melonion.me/subscription/form">
|
||||
<input type="hidden" name="list_id" value="3">
|
||||
<input type="text" name="name" placeholder="Your Name" required>
|
||||
<input type="email" name="email" placeholder="Your Email" required>
|
||||
|
|
|
@ -2,9 +2,12 @@ import express from 'express';
|
|||
import dotenv from 'dotenv';
|
||||
import path from 'path'; // Import the path module
|
||||
import routes from './src/routes.js'; // Import routes from routes.js
|
||||
import { validateEnvVariables } from './src/envValidator.js';
|
||||
|
||||
dotenv.config();
|
||||
|
||||
validateEnvVariables();
|
||||
|
||||
const app = express();
|
||||
const PORT = process.env.PORT || 3002;
|
||||
|
||||
|
|
16
src/envValidator.js
Normal file
16
src/envValidator.js
Normal file
|
@ -0,0 +1,16 @@
|
|||
export function validateEnvVariables() {
|
||||
const requiredVars = [
|
||||
'LISTMONK_URL',
|
||||
'LISTMONK_USERNAME',
|
||||
'LISTMONK_PASSWORD',
|
||||
'LIST_ID'
|
||||
];
|
||||
|
||||
const missingVars = requiredVars.filter((variable) => !process.env[variable]);
|
||||
|
||||
if (missingVars.length > 0) {
|
||||
console.error(`Error: Missing environment variables: ${missingVars.join(', ')}`);
|
||||
process.exit(1); // Exit the application with a failure code
|
||||
}
|
||||
console.log('All required environment variables are set.');
|
||||
}
|
Loading…
Add table
Reference in a new issue