Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

459 add definitions for important env variables to readme #491

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 1 addition & 16 deletions .env
Original file line number Diff line number Diff line change
@@ -1,19 +1,4 @@
# Development Environment Configuration
NODE_ENV=development
PORT=3000
# Database Configuration
DEV_DB_USERNAME=user123
DEV_DB_PASSWORD=password123
DEV_DB_NAME=onboarding_db
DEV_DB_HOST=localhost
DEV_DB_PORT=5432

# JWT Secret Key
JWT_SECRET="NKrbO2lpCsOpVAlqAPsjZ0tZXzIoKru7gAmYZ7XlHn0=qqwqeq"

[email protected]
EMAIL_PASSWORD=passwor
EMAIL_HOST=smtp.gmail.com
EMAIL_PORT=465
APP_PASSWORD=ukzwakckupguegiw
EMAIL_ENABLE=false
JWT_SECRET="NKrbO2lpCsOpVAlqAPsjZ0tZXzIoKru7gAmYZ7XlHn0=qqwqeq"
40 changes: 28 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,26 +127,37 @@ docker compose up -d`

## Environment variables

In order to the project to run safely and correctly, the user should add their own environment variables. They can be added to the .env file in the root directory of the project. The following is the list of environment variables that should be added and its description:
In order to the project to run safely and correctly, the user should add their own environment variables. They can be added to the .env file in the backend directory of the project. The following is the list of environment variables that should be added and its description:

1. Node Env

```env
NODE_ENV - node environment (production, test or development)
```

It is set from the .env file in the root directory

2.

```
API_BASE_URL - Backend API url
```

It is set from ./frontend/src/utils/constant.js

1. Database credentials

```env
DEV_DB_USERNAME - Development database username
DEV_DB_PASSWORD - Development database password
DEV_DB_NAME - Development database name
DEV_DB_HOST - Development database host
DEV_DB_PORT - Development database port
DB_USERNAME - Database username
DB_PASSWORD - Database password
DB_NAME - Database name
DB_HOST - Database host
DB_PORT - Database port
TEST_DB_USERNAME - Test database username
TEST_DB_PASSWORD - Test database password
TEST_DB_NAME - Test database name
TEST_DB_HOST - Test database host
TEST_DB_PORT - Test database port
PROD_DB_USERNAME - Production database username
PROD_DB_PASSWORD - Production database password
PROD_DB_NAME - Production database name
PROD_DB_HOST - Production database host
PROD_DB_PORT - Production database port
```

2. Email service configuration
Expand All @@ -158,6 +169,7 @@ EMAIL_HOST - Email host
EMAIL_PORT - Email port
EMAIL - Email
APP_PASSWORD - Email password
FRONTEND_URL - Url of the frontend server
```

Example configuration:
Expand All @@ -168,6 +180,7 @@ EMAIL_HOST=smtp.gmail.com
EMAIL_PORT=587
[email protected]
APP_PASSWORD=your-app-specific-password
FRONTEND_URL=https://www.frontendserver.com
```

Note: When using Gmail, you'll need to enable 2-factor authentication and generate an App Password.
Expand All @@ -180,6 +193,8 @@ JWT_SECRET - secret key to sign the JWT token

- Use a strong, random secret key (minimum 32 characters)

- Docker uses the JWT Secret on `.env`. If you run `npm run dev` locally in backend folder it uses the JWT Secret in `./backend/.env`

4. Enable IP check for the API
If the ENABLE_IP_CHECK is set to true, but the ALLOWED_IP_RANGE and ALLOWED_IPS are not set, the API will work for all IP addresses.

Expand Down Expand Up @@ -207,7 +222,8 @@ POSTGRES_PASSWORD - Test database password (The same as TEST_DB_PASSWORD)
POSTGRES_DB - Test database name (The same as TEST_DB_NAME)
```

For development and testing purposes, the application is ready to go after cloning and dependencies installation.
For running tests in windows installing `win-node-env` module is recommended


## Contributing

Expand Down
18 changes: 9 additions & 9 deletions backend/.env
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
# For development environment, the project is ready to run after cloning and installing the dependencies.
# Development database environment
DEV_DB_USERNAME=user123
DEV_DB_PASSWORD=password123
DEV_DB_NAME=onboarding_db
DEV_DB_HOST=db
DEV_DB_PORT=5432

# JWT Secret Key
JWT_SECRET="NKrbO2lpCsOpVAlqAPsjZ0tZXzIoKru7gAmYZ7XlHn0=qqwqeq"
DB_USERNAME=user123
DB_PASSWORD=password123
DB_NAME=onboarding_db
DB_HOST=db
DB_PORT=5432

[email protected]
EMAIL_PASSWORD=passwor
Expand All @@ -24,4 +21,7 @@ ALLOWED_IP_RANGE=11.22.33/10-200, 192.168.65/1-255
ALLOWED_IPS=127.0.0.1, 11.22.33.44, 11.22.33.45, 11.22.33.46, 192.168.65.1

# FRONTEND_URL=https://onboarding-demo.bluewavelabs.ca/
FRONTEND_URL=http://localhost:4173/
FRONTEND_URL=http://localhost:4173/

# JWT secret for running npm run dev in backend folder locally
JWT_SECRET="NKrbO2lpCsOpVAlqAPsjZ0tZXzIoKru7gAmYZ7XlHn0=qqwqeq"
24 changes: 0 additions & 24 deletions backend/.env.production

This file was deleted.

24 changes: 5 additions & 19 deletions backend/.env.test
Original file line number Diff line number Diff line change
@@ -1,26 +1,12 @@
# Test Environment Configuration

# Test database environment
POSTGRES_USER=user123
POSTGRES_PASSWORD=password123
POSTGRES_DB=onboarding_db_test

TEST_DB_USERNAME=user123
TEST_DB_PASSWORD=password123
TEST_DB_NAME=onboarding_db_test
TEST_DB_HOST=localhost
TEST_DB_PORT=5432

# Credentials for test postgres database
POSTGRES_USER=user123
POSTGRES_PASSWORD=password123
POSTGRES_DB=onboarding_db_test

# Enable email service
EMAIL_ENABLE=false

# JWT Secret Key
JWT_SECRET=your_test_jwt_secret_key_here

# Enable IP check for the API
ENABLE_IP_CHECK=false
# Allowed IP range for the API "baseIp/rangeStart-rangeEnd" (e.g. 192.168.1/1-255) separated by comma
ALLOWED_IP_RANGE=11.22.33/10-200, 192.168.65/1-255
# Allowed IP addresses for the API separated by comma
ALLOWED_IPS=127.0.0.1, 11.22.33.44, 11.22.33.45, 11.22.33.46, 192.168.65.1
JWT_SECRET="NKrbO2lpCsOpVAlqAPsjZ0tZXzIoKru7gAmYZ7XlHn0=qqwqeq"
35 changes: 15 additions & 20 deletions backend/config/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,32 +11,27 @@ if (result.error) {
}

const {
DEV_DB_HOST,
DEV_DB_NAME,
DEV_DB_PASSWORD,
DEV_DB_PORT,
DEV_DB_USERNAME,
DB_HOST,
DB_NAME,
DB_PASSWORD,
DB_PORT,
DB_USERNAME,
TEST_DB_HOST,
TEST_DB_NAME,
TEST_DB_PASSWORD,
TEST_DB_PORT,
TEST_DB_USERNAME,
PROD_DB_HOST,
PROD_DB_NAME,
PROD_DB_PASSWORD,
PROD_DB_PORT,
PROD_DB_USERNAME,
} = process.env;

module.exports = {
defaultTeamName: 'My Organisation',
development: {
username: DEV_DB_USERNAME,
password: DEV_DB_PASSWORD,
database: DEV_DB_NAME,
host: DEV_DB_HOST,
username: DB_USERNAME,
password: DB_PASSWORD,
database: DB_NAME,
host: DB_HOST,
dialect: 'postgres',
port: DEV_DB_PORT,
port: DB_PORT,
logging: false,
},
test: {
Expand All @@ -49,12 +44,12 @@ module.exports = {
logging: false,
},
production: {
username: PROD_DB_USERNAME,
password: PROD_DB_PASSWORD,
database: PROD_DB_NAME,
host: PROD_DB_HOST,
username: DB_USERNAME,
password: DB_PASSWORD,
database: DB_NAME,
host: DB_HOST,
dialect: 'postgres',
port: PROD_DB_PORT,
port: DB_PORT,
logging: false,
},
};
15 changes: 9 additions & 6 deletions backend/src/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const cors = require("cors");
const helmet = require("helmet");
const dotenv = require("dotenv");
const bodyParser = require("body-parser");
// const compression = require("compression");
const compression = require("compression");
const jsonErrorMiddleware = require("./middleware/jsonError.middleware");
const fileSizeValidator = require("./middleware/fileSizeValidator.middleware");
const { MAX_FILE_SIZE } = require("./utils/constants.helper");
Expand Down Expand Up @@ -32,24 +32,27 @@ app.use(cors());
app.options('*', cors()); // this is for preflight requests
app.use(helmet());
app.use(bodyParser.json({ limit: MAX_FILE_SIZE }));
// app.use(compression());
app.use(compression());
app.use(jsonErrorMiddleware);
if (process.env.ENABLE_IP_CHECK === 'true') {
app.use(ipFilter);
}
// app.use(fileSizeValidator);


const { sequelize } = require("./models");

sequelize
.authenticate()
.then(() => console.log("Database connected..."))
.catch((err) => console.log("Error: " + err));

sequelize
.sync({ alter: true })
.then(() => console.log("Models synced with the database..."))
.catch((err) => console.log("Error syncing models: " + err));
if (process.env.NODE_ENV == 'development') {
sequelize
.sync({ alter: true })
.then(() => console.log("Models synced with the database..."))
.catch((err) => console.log("Error syncing models: " + err));
}

app.use("/api/auth", authRoutes);
app.use("/api/users", userRoutes);
Expand Down
7 changes: 3 additions & 4 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ services:
- ./backend/.env
environment:
- NODE_ENV=${NODE_ENV}
- PORT=${PORT}
- JWT_SECRET=${JWT_SECRET}
- EMAIL=${EMAIL}
- EMAIL_PASSWORD=${EMAIL_PASSWORD}
Expand Down Expand Up @@ -52,9 +51,9 @@ services:
env_file:
- ./backend/.env
environment:
- POSTGRES_USER=${DEV_DB_USERNAME}
- POSTGRES_PASSWORD=${DEV_DB_PASSWORD}
- POSTGRES_DB=${DEV_DB_NAME}
- POSTGRES_USER=${DB_USERNAME}
- POSTGRES_PASSWORD=${DB_PASSWORD}
- POSTGRES_DB=${DB_NAME}
ports:
- "5432:5432"
volumes:
Expand Down
4 changes: 1 addition & 3 deletions frontend/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ COPY . .

ENV NODE_OPTIONS="--max-old-space-size=4096"

RUN npm run build

EXPOSE 4173

CMD ["npm", "run", "preview"]
CMD ["sh", "-c", "npm run build && npm run preview"]
Loading