backend changes
This commit is contained in:
parent
a9964e906d
commit
91cfe9dd50
@ -6,13 +6,14 @@
|
|||||||
// ========================================
|
// ========================================
|
||||||
// LIVE PRODUCTION URLS (Currently Active)
|
// LIVE PRODUCTION URLS (Currently Active)
|
||||||
// ========================================
|
// ========================================
|
||||||
const FRONTEND_URL = 'http://192.168.1.31:3001';
|
const FRONTEND_URL = 'https://dashboard.codenuk.com';
|
||||||
const BACKEND_URL = 'https://backend.codenuk.com';
|
const BACKEND_URL = 'https://backend.codenuk.com';
|
||||||
|
|
||||||
|
|
||||||
// ========================================
|
// ========================================
|
||||||
// const FRONTEND_URL = 'http://localhost:3001';
|
// LOCAL DEVELOPMENT URLS
|
||||||
// const BACKEND_URL = 'http://localhost:8000';
|
// ========================================
|
||||||
|
// const FRONTEND_URL = 'http://192.168.1.16:3001';
|
||||||
|
// const BACKEND_URL = 'http://192.168.1.16:8000';
|
||||||
|
|
||||||
// ========================================
|
// ========================================
|
||||||
// CORS CONFIGURATION (Auto-generated)
|
// CORS CONFIGURATION (Auto-generated)
|
||||||
|
|||||||
@ -233,8 +233,7 @@ services:
|
|||||||
- NODE_ENV=development
|
- NODE_ENV=development
|
||||||
- PORT=8000
|
- PORT=8000
|
||||||
- HOST=0.0.0.0
|
- HOST=0.0.0.0
|
||||||
- FRONTEND_URL=http://192.168.1.31:3001 # Allow all URLs
|
- CORS_ORIGINS=https://dashboard.codenuk.com
|
||||||
- CORS_ORIGINS=* # Allow all URLs
|
|
||||||
- CORS_METHODS=GET,POST,PUT,DELETE,PATCH,OPTIONS # Add this line
|
- CORS_METHODS=GET,POST,PUT,DELETE,PATCH,OPTIONS # Add this line
|
||||||
- CORS_CREDENTIALS=true # Add this line
|
- CORS_CREDENTIALS=true # Add this line
|
||||||
# Database connections
|
# Database connections
|
||||||
@ -507,7 +506,6 @@ services:
|
|||||||
- JWT_ACCESS_EXPIRY=24h
|
- JWT_ACCESS_EXPIRY=24h
|
||||||
- JWT_ADMIN_ACCESS_EXPIRY=7d
|
- JWT_ADMIN_ACCESS_EXPIRY=7d
|
||||||
- JWT_REFRESH_EXPIRY=7d
|
- JWT_REFRESH_EXPIRY=7d
|
||||||
- FRONTEND_URL=http://192.168.1.31:3001
|
|
||||||
# Email Configuration
|
# Email Configuration
|
||||||
- SMTP_HOST=smtp.gmail.com
|
- SMTP_HOST=smtp.gmail.com
|
||||||
- SMTP_PORT=587
|
- SMTP_PORT=587
|
||||||
@ -613,7 +611,6 @@ services:
|
|||||||
environment:
|
environment:
|
||||||
- PORT=8012
|
- PORT=8012
|
||||||
- HOST=0.0.0.0
|
- HOST=0.0.0.0
|
||||||
- FRONTEND_URL=http://192.168.1.31:3001
|
|
||||||
- POSTGRES_HOST=postgres
|
- POSTGRES_HOST=postgres
|
||||||
- POSTGRES_PORT=5432
|
- POSTGRES_PORT=5432
|
||||||
- POSTGRES_DB=dev_pipeline
|
- POSTGRES_DB=dev_pipeline
|
||||||
|
|||||||
@ -28,9 +28,10 @@ RABBITMQ_USER=pipeline_admin
|
|||||||
RABBITMQ_PASSWORD=secure_rabbitmq_password
|
RABBITMQ_PASSWORD=secure_rabbitmq_password
|
||||||
|
|
||||||
# CORS
|
# CORS
|
||||||
FRONTEND_URL=http://192.168.1.31:3001
|
FRONTEND_URL=http://192.168.1.16:3001
|
||||||
|
|
||||||
# CORS Configuration
|
# CORS Configuration
|
||||||
CORS_ORIGIN=http://192.168.1.31:3001
|
CORS_ORIGIN=http://192.168.1.16:3001
|
||||||
CORS_METHODS=GET,POST,PUT,DELETE,PATCH,OPTIONS
|
CORS_METHODS=GET,POST,PUT,DELETE,PATCH,OPT
|
||||||
|
IONS
|
||||||
CORS_CREDENTIALS=true
|
CORS_CREDENTIALS=true
|
||||||
@ -63,25 +63,121 @@ router.post('/register', registerRateLimit, validateRegistration, async (req, re
|
|||||||
router.get('/verify-email', async (req, res) => {
|
router.get('/verify-email', async (req, res) => {
|
||||||
try {
|
try {
|
||||||
const { token } = req.query;
|
const { token } = req.query;
|
||||||
|
|
||||||
|
if (!token) {
|
||||||
|
// Use centralized config instead of environment variables
|
||||||
|
let frontendUrl;
|
||||||
|
try {
|
||||||
|
const urls = require('../../../../config/urls');
|
||||||
|
frontendUrl = urls.FRONTEND_URL || 'http://192.168.1.16:3001';
|
||||||
|
} catch (err) {
|
||||||
|
frontendUrl = 'http://192.168.1.16:3001';
|
||||||
|
}
|
||||||
|
const redirectUrl = `${frontendUrl}/signin?error=${encodeURIComponent('Verification token is required')}`;
|
||||||
|
if (req.query.format === 'json') {
|
||||||
|
return res.status(400).json({ success: false, message: 'Verification token is required', redirect: redirectUrl });
|
||||||
|
}
|
||||||
|
return res.redirect(302, redirectUrl);
|
||||||
|
}
|
||||||
|
|
||||||
await authService.verifyEmailToken(token);
|
await authService.verifyEmailToken(token);
|
||||||
|
|
||||||
const frontendUrl = process.env.FRONTEND_URL || 'http://192.168.1.31:3001';
|
// Use centralized config instead of environment variables
|
||||||
|
let frontendUrl;
|
||||||
|
try {
|
||||||
|
const urls = require('../../../../config/urls');
|
||||||
|
frontendUrl = urls.FRONTEND_URL || 'http://192.168.1.16:3001';
|
||||||
|
} catch (err) {
|
||||||
|
frontendUrl = 'http://192.168.1.16:3001';
|
||||||
|
}
|
||||||
const redirectUrl = `${frontendUrl}/signin?verified=true`;
|
const redirectUrl = `${frontendUrl}/signin?verified=true`;
|
||||||
|
|
||||||
|
console.log(`✅ Email verification successful, redirecting to: ${redirectUrl}`);
|
||||||
|
|
||||||
// Prefer redirect by default; only return JSON if explicitly requested
|
// Prefer redirect by default; only return JSON if explicitly requested
|
||||||
if (req.query.format === 'json') {
|
if (req.query.format === 'json') {
|
||||||
return res.json({ success: true, message: 'Email verified successfully', redirect: redirectUrl });
|
return res.json({
|
||||||
|
success: true,
|
||||||
|
message: 'Email verified successfully',
|
||||||
|
redirect: redirectUrl
|
||||||
|
});
|
||||||
}
|
}
|
||||||
return res.redirect(302, redirectUrl);
|
return res.redirect(302, redirectUrl);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
const frontendUrl = process.env.FRONTEND_URL || 'http://192.168.1.31:3001';
|
// Use centralized config instead of environment variables
|
||||||
|
let frontendUrl;
|
||||||
|
try {
|
||||||
|
const urls = require('../../../../config/urls');
|
||||||
|
frontendUrl = urls.FRONTEND_URL || 'http://192.168.1.16:3001';
|
||||||
|
} catch (err) {
|
||||||
|
frontendUrl = 'http://192.168.1.16:3001';
|
||||||
|
}
|
||||||
const redirectUrl = `${frontendUrl}/signin?error=${encodeURIComponent(error.message)}`;
|
const redirectUrl = `${frontendUrl}/signin?error=${encodeURIComponent(error.message)}`;
|
||||||
|
|
||||||
|
console.error(`❌ Email verification failed: ${error.message}, redirecting to: ${redirectUrl}`);
|
||||||
|
|
||||||
if (req.query.format === 'json') {
|
if (req.query.format === 'json') {
|
||||||
return res.status(400).json({ success: false, message: error.message, redirect: redirectUrl });
|
return res.status(400).json({
|
||||||
|
success: false,
|
||||||
|
message: error.message,
|
||||||
|
redirect: redirectUrl
|
||||||
|
});
|
||||||
}
|
}
|
||||||
return res.redirect(302, redirectUrl);
|
return res.redirect(302, redirectUrl);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// POST /api/auth/resend-verification - Resend verification email
|
||||||
|
router.post('/resend-verification', async (req, res) => {
|
||||||
|
try {
|
||||||
|
const { email } = req.body;
|
||||||
|
|
||||||
|
if (!email) {
|
||||||
|
return res.status(400).json({
|
||||||
|
success: false,
|
||||||
|
error: 'Email is required',
|
||||||
|
message: 'Please provide an email address'
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Find user by email
|
||||||
|
const user = await User.findByEmail(email);
|
||||||
|
if (!user) {
|
||||||
|
return res.status(404).json({
|
||||||
|
success: false,
|
||||||
|
error: 'User not found',
|
||||||
|
message: 'No account found with this email address'
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if already verified
|
||||||
|
if (user.email_verified) {
|
||||||
|
return res.status(400).json({
|
||||||
|
success: false,
|
||||||
|
error: 'Already verified',
|
||||||
|
message: 'This email address is already verified'
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Send verification email
|
||||||
|
await authService.sendVerificationEmail(user);
|
||||||
|
|
||||||
|
console.log(`📧 Verification email resent to: ${email}`);
|
||||||
|
|
||||||
|
res.json({
|
||||||
|
success: true,
|
||||||
|
message: 'Verification email sent successfully. Please check your inbox.'
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
console.error('❌ Resend verification failed:', error.message);
|
||||||
|
res.status(500).json({
|
||||||
|
success: false,
|
||||||
|
error: 'Failed to resend verification',
|
||||||
|
message: error.message
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
// POST /api/auth/login - User login
|
// POST /api/auth/login - User login
|
||||||
router.post('/login', loginRateLimit , validateLogin, async (req, res) => {
|
router.post('/login', loginRateLimit , validateLogin, async (req, res) => {
|
||||||
try {
|
try {
|
||||||
|
|||||||
@ -148,32 +148,29 @@ class AuthService {
|
|||||||
|
|
||||||
async sendVerificationEmail(user) {
|
async sendVerificationEmail(user) {
|
||||||
const token = await this.createEmailVerificationToken(user.id);
|
const token = await this.createEmailVerificationToken(user.id);
|
||||||
// Resolve verification URL. Prefer environment variable (works in Docker). If not present,
|
// Use centralized URL configuration - no environment variables needed
|
||||||
// fall back to the repository-level config/urls.js when available (development).
|
|
||||||
let verifyUrl;
|
let verifyUrl;
|
||||||
const frontendUrlFromEnv = process.env.FRONTEND_URL;
|
try {
|
||||||
if (frontendUrlFromEnv) {
|
// Load centralized config from repository root
|
||||||
const FRONTEND_URL = frontendUrlFromEnv.replace(/\/$/, '');
|
// eslint-disable-next-line global-require
|
||||||
verifyUrl = `${FRONTEND_URL}/verify-email?token=${encodeURIComponent(token)}`;
|
const urls = require('../../../../config/urls');
|
||||||
} else {
|
if (urls && typeof urls.getVerificationUrl === 'function') {
|
||||||
try {
|
verifyUrl = urls.getVerificationUrl(token);
|
||||||
// Attempt to load repo-level config (works when running locally from repo root)
|
} else if (urls && urls.FRONTEND_URL) {
|
||||||
// This is guarded so it won't crash inside Docker if the relative path isn't valid.
|
const FRONTEND_URL = urls.FRONTEND_URL.replace(/\/$/, '');
|
||||||
// eslint-disable-next-line global-require
|
verifyUrl = `${FRONTEND_URL}/verify-email?token=${encodeURIComponent(token)}`;
|
||||||
const urls = require('../../../../config/urls');
|
} else {
|
||||||
if (urls && typeof urls.getVerificationUrl === 'function') {
|
// Hardcoded fallback - no environment variables
|
||||||
verifyUrl = urls.getVerificationUrl(token);
|
verifyUrl = `http://192.168.1.16:3001/verify-email?token=${encodeURIComponent(token)}`;
|
||||||
} else if (urls && urls.FRONTEND_URL) {
|
|
||||||
const FRONTEND_URL = urls.FRONTEND_URL.replace(/\/$/, '');
|
|
||||||
verifyUrl = `${FRONTEND_URL}/verify-email?token=${encodeURIComponent(token)}`;
|
|
||||||
}
|
|
||||||
} catch (err) {
|
|
||||||
// As a last resort, build a relative backend-hosted verification endpoint
|
|
||||||
const backendHost = process.env.BACKEND_URL || `http://localhost:${process.env.PORT || 8011}`;
|
|
||||||
verifyUrl = `${backendHost.replace(/\/$/, '')}/api/auth/verify-email?token=${encodeURIComponent(token)}`;
|
|
||||||
}
|
}
|
||||||
|
} catch (err) {
|
||||||
|
// Hardcoded fallback - no environment variables
|
||||||
|
verifyUrl = `http://192.168.1.16:3001/verify-email?token=${encodeURIComponent(token)}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
console.log(`📧 Generated verification URL: ${verifyUrl}`);
|
||||||
|
console.log(`📧 Using centralized URL config`);
|
||||||
|
|
||||||
const today = new Date();
|
const today = new Date();
|
||||||
const dateString = today.toLocaleDateString('en-US');
|
const dateString = today.toLocaleDateString('en-US');
|
||||||
|
|
||||||
|
|||||||
@ -241,7 +241,7 @@ import axios from 'axios';
|
|||||||
|
|
||||||
// Configure API client for requirement processor
|
// Configure API client for requirement processor
|
||||||
const apiClient = axios.create({
|
const apiClient = axios.create({
|
||||||
baseURL: 'http://localhost:8001', // Direct to requirement processor
|
baseURL: 'https://backend.codenuk.com/api/requirements', // Via API gateway
|
||||||
timeout: 30000,
|
timeout: 30000,
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
@ -250,7 +250,7 @@ const apiClient = axios.create({
|
|||||||
|
|
||||||
// Configure API client for Template-Manager service
|
// Configure API client for Template-Manager service
|
||||||
const templateApiClient = axios.create({
|
const templateApiClient = axios.create({
|
||||||
baseURL: 'http://localhost:8009', // Direct to template-manager
|
baseURL: 'https://backend.codenuk.com/api/templates', // Via API gateway
|
||||||
timeout: 30000,
|
timeout: 30000,
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
@ -259,7 +259,7 @@ const templateApiClient = axios.create({
|
|||||||
|
|
||||||
// Configure API client for User-Auth service
|
// Configure API client for User-Auth service
|
||||||
const authApiClient = axios.create({
|
const authApiClient = axios.create({
|
||||||
baseURL: 'http://localhost:8011', // Direct to user-auth
|
baseURL: 'https://backend.codenuk.com/api/auth', // Via API gateway
|
||||||
timeout: 30000,
|
timeout: 30000,
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user