mirror of
https://github.com/DeNNiiInc/Connect-5.git
synced 2026-04-17 18:26:01 +00:00
Security: Move database credentials to separate config file
This commit is contained in:
23
.gitignore
vendored
Normal file
23
.gitignore
vendored
Normal file
@@ -0,0 +1,23 @@
|
||||
# Database configuration with credentials
|
||||
db.config.js
|
||||
|
||||
# Node modules
|
||||
node_modules/
|
||||
|
||||
# Environment variables
|
||||
.env
|
||||
.env.local
|
||||
|
||||
# Logs
|
||||
logs/
|
||||
*.log
|
||||
|
||||
# OS files
|
||||
.DS_Store
|
||||
Thumbs.db
|
||||
|
||||
# IDE files
|
||||
.vscode/
|
||||
.idea/
|
||||
*.swp
|
||||
*.swo
|
||||
125
README_DB_CONFIG.md
Normal file
125
README_DB_CONFIG.md
Normal file
@@ -0,0 +1,125 @@
|
||||
# Database Configuration Setup
|
||||
|
||||
## Overview
|
||||
Database credentials are stored in a separate configuration file (`db.config.js`) that is **NOT committed to GitHub** for security reasons.
|
||||
|
||||
## Files
|
||||
|
||||
### 1. `db.config.example.js` (Committed to Git)
|
||||
Template file showing the required configuration structure.
|
||||
|
||||
### 2. `db.config.js` (NOT Committed - in .gitignore)
|
||||
Contains actual database credentials. This file must be created manually.
|
||||
|
||||
### 3. `.gitignore`
|
||||
Ensures `db.config.js` is never committed to the repository.
|
||||
|
||||
## Setup Instructions
|
||||
|
||||
### For Local Development
|
||||
|
||||
1. **Copy the example file:**
|
||||
```bash
|
||||
cp db.config.example.js db.config.js
|
||||
```
|
||||
|
||||
2. **Edit `db.config.js` with your credentials:**
|
||||
```javascript
|
||||
module.exports = {
|
||||
host: 'localhost', // or your database host
|
||||
user: 'your_username',
|
||||
password: 'your_password',
|
||||
database: 'appgconnect5_db',
|
||||
waitForConnections: true,
|
||||
connectionLimit: 10,
|
||||
queueLimit: 0
|
||||
};
|
||||
```
|
||||
|
||||
3. **Start the server:**
|
||||
```bash
|
||||
npm start
|
||||
```
|
||||
|
||||
### For Production Deployment
|
||||
|
||||
1. **Pull the latest code on your server:**
|
||||
```bash
|
||||
git pull origin main
|
||||
```
|
||||
|
||||
2. **Create `db.config.js` on the production server:**
|
||||
```bash
|
||||
nano db.config.js
|
||||
# or
|
||||
vi db.config.js
|
||||
```
|
||||
|
||||
3. **Add your production database credentials:**
|
||||
```javascript
|
||||
module.exports = {
|
||||
host: 'your-production-db-host.com',
|
||||
user: 'production_user',
|
||||
password: 'secure_production_password',
|
||||
database: 'appgconnect5_db',
|
||||
waitForConnections: true,
|
||||
connectionLimit: 10,
|
||||
queueLimit: 0
|
||||
};
|
||||
```
|
||||
|
||||
4. **Save and restart the server:**
|
||||
```bash
|
||||
pm2 restart connect5
|
||||
# or your restart command
|
||||
```
|
||||
|
||||
## Security Features
|
||||
|
||||
✅ **Credentials not in git** - `db.config.js` is in `.gitignore`
|
||||
✅ **Template provided** - `db.config.example.js` shows the structure
|
||||
✅ **Comments in code** - Clear instructions in `database.js`
|
||||
✅ **Separate config** - Easy to update without touching main code
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
### Error: Cannot find module './db.config.js'
|
||||
|
||||
**Solution:** You need to create the `db.config.js` file:
|
||||
```bash
|
||||
cp db.config.example.js db.config.js
|
||||
# Then edit with your credentials
|
||||
```
|
||||
|
||||
### Error: Access denied for user
|
||||
|
||||
**Solution:** Check your credentials in `db.config.js`:
|
||||
- Verify username
|
||||
- Verify password
|
||||
- Check host address
|
||||
- Ensure user has proper permissions
|
||||
|
||||
### Connection timeout
|
||||
|
||||
**Solution:**
|
||||
- Check if MySQL server is running
|
||||
- Verify firewall allows connection
|
||||
- Check host address is correct
|
||||
|
||||
## Important Notes
|
||||
|
||||
⚠️ **NEVER commit `db.config.js` to git**
|
||||
⚠️ **Keep production credentials secure**
|
||||
⚠️ **Use different credentials for dev/prod**
|
||||
⚠️ **Regularly rotate passwords**
|
||||
|
||||
## File Structure
|
||||
|
||||
```
|
||||
Connect-5/
|
||||
├── db.config.example.js ← Template (in git)
|
||||
├── db.config.js ← Your credentials (NOT in git)
|
||||
├── .gitignore ← Protects db.config.js
|
||||
├── database.js ← Imports from db.config.js
|
||||
└── README_DB_CONFIG.md ← This file
|
||||
```
|
||||
14
database.js
14
database.js
@@ -1,15 +1,9 @@
|
||||
const mysql = require('mysql2/promise');
|
||||
|
||||
// Database configuration
|
||||
const dbConfig = {
|
||||
host: 'oceprod.beyondcloud.solutions',
|
||||
user: 'appgconnect5_dbuser',
|
||||
password: 'REqTtHhZCKAlJAnznjLx8ZhOq',
|
||||
database: 'appgconnect5_db',
|
||||
waitForConnections: true,
|
||||
connectionLimit: 10,
|
||||
queueLimit: 0
|
||||
};
|
||||
// Import database configuration from external file
|
||||
// This file (db.config.js) is not committed to git for security
|
||||
// Use db.config.example.js as a template
|
||||
const dbConfig = require('./db.config.js');
|
||||
|
||||
// Create connection pool
|
||||
const pool = mysql.createPool(dbConfig);
|
||||
|
||||
13
db.config.example.js
Normal file
13
db.config.example.js
Normal file
@@ -0,0 +1,13 @@
|
||||
// Database Configuration File
|
||||
// IMPORTANT: This file contains sensitive credentials and should NEVER be committed to git
|
||||
// Copy this file to db.config.js and update with your actual database credentials
|
||||
|
||||
module.exports = {
|
||||
host: 'your-database-host.com',
|
||||
user: 'your-database-username',
|
||||
password: 'your-secure-password',
|
||||
database: 'your-database-name',
|
||||
waitForConnections: true,
|
||||
connectionLimit: 10,
|
||||
queueLimit: 0
|
||||
};
|
||||
Reference in New Issue
Block a user