Added .env configuration to remove hardcoded IP issues

This commit is contained in:
2026-01-28 09:23:30 -07:00
parent 88c33cae04
commit 60f0424235
5 changed files with 25 additions and 7 deletions

4
backend/.env.example Normal file
View File

@@ -0,0 +1,4 @@
# Backend Configuration
PORT=3001
API_HOST=localhost
CORS_ORIGINS=http://localhost:3000

View File

@@ -1,5 +1,7 @@
// CVE Management Backend API
// Install: npm install express sqlite3 multer cors
// Install: npm install express sqlite3 multer cors dotenv
require('dotenv').config();
const express = require('express');
const sqlite3 = require('sqlite3').verbose();
@@ -9,7 +11,11 @@ const path = require('path');
const fs = require('fs');
const app = express();
const PORT = 3001;
const PORT = process.env.PORT || 3001;
const API_HOST = process.env.API_HOST || 'localhost';
const CORS_ORIGINS = process.env.CORS_ORIGINS
? process.env.CORS_ORIGINS.split(',')
: ['http://localhost:3000'];
// Log all incoming requests
app.use((req, res, next) => {
@@ -19,7 +25,7 @@ app.use((req, res, next) => {
// Middleware
app.use(cors({
origin: ['http://localhost:3000', 'http://192.168.2.117:3000'],
origin: CORS_ORIGINS,
credentials: true
}));
app.use(express.json());
@@ -382,5 +388,6 @@ app.get('/api/stats', (req, res) => {
// Start server
app.listen(PORT, () => {
console.log(`CVE API server running on http://localhost:${PORT}`);
console.log(`CVE API server running on http://${API_HOST}:${PORT}`);
console.log(`CORS origins: ${CORS_ORIGINS.join(', ')}`);
});

5
frontend/.env.example Normal file
View File

@@ -0,0 +1,5 @@
# Frontend Configuration
# API_BASE should include the /api path
REACT_APP_API_BASE=http://localhost:3001/api
# API_HOST is used for direct file URLs (no /api)
REACT_APP_API_HOST=http://localhost:3001

View File

@@ -1,7 +1,8 @@
import React, { useState, useEffect } from 'react';
import { Search, FileText, AlertCircle, Download, Upload, Eye, Filter, CheckCircle, XCircle, Loader, Trash2, Plus } from 'lucide-react';
const API_BASE = 'http://192.168.2.117:3001/api';
const API_BASE = process.env.REACT_APP_API_BASE || 'http://localhost:3001/api';
const API_HOST = process.env.REACT_APP_API_HOST || 'http://localhost:3001';
const severityLevels = ['All Severities', 'Critical', 'High', 'Medium', 'Low'];
@@ -626,7 +627,7 @@ export default function App() {
</div>
<div className="flex gap-2">
<a
href={`http://192.168.2.117:3001/${doc.file_path}`}
href={`${API_HOST}/${doc.file_path}`}
target="_blank"
rel="noopener noreferrer"
className="px-3 py-1 text-sm text-[#0476D9] hover:bg-blue-50 rounded transition-colors border border-[#0476D9]"

View File

@@ -11,6 +11,7 @@
"license": "ISC",
"dependencies": {
"cors": "^2.8.6",
"dotenv": "^16.6.1",
"express": "^5.2.1",
"multer": "^2.0.2",
"sqlite3": "^5.1.7"