Added .env configuration to remove hardcoded IP issues
This commit is contained in:
4
backend/.env.example
Normal file
4
backend/.env.example
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
# Backend Configuration
|
||||||
|
PORT=3001
|
||||||
|
API_HOST=localhost
|
||||||
|
CORS_ORIGINS=http://localhost:3000
|
||||||
@@ -1,5 +1,7 @@
|
|||||||
// CVE Management Backend API
|
// 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 express = require('express');
|
||||||
const sqlite3 = require('sqlite3').verbose();
|
const sqlite3 = require('sqlite3').verbose();
|
||||||
@@ -9,7 +11,11 @@ const path = require('path');
|
|||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
|
|
||||||
const app = express();
|
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
|
// Log all incoming requests
|
||||||
app.use((req, res, next) => {
|
app.use((req, res, next) => {
|
||||||
@@ -19,7 +25,7 @@ app.use((req, res, next) => {
|
|||||||
|
|
||||||
// Middleware
|
// Middleware
|
||||||
app.use(cors({
|
app.use(cors({
|
||||||
origin: ['http://localhost:3000', 'http://192.168.2.117:3000'],
|
origin: CORS_ORIGINS,
|
||||||
credentials: true
|
credentials: true
|
||||||
}));
|
}));
|
||||||
app.use(express.json());
|
app.use(express.json());
|
||||||
@@ -382,5 +388,6 @@ app.get('/api/stats', (req, res) => {
|
|||||||
|
|
||||||
// Start server
|
// Start server
|
||||||
app.listen(PORT, () => {
|
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
5
frontend/.env.example
Normal 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
|
||||||
@@ -1,7 +1,8 @@
|
|||||||
import React, { useState, useEffect } from 'react';
|
import React, { useState, useEffect } from 'react';
|
||||||
import { Search, FileText, AlertCircle, Download, Upload, Eye, Filter, CheckCircle, XCircle, Loader, Trash2, Plus } from 'lucide-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'];
|
const severityLevels = ['All Severities', 'Critical', 'High', 'Medium', 'Low'];
|
||||||
|
|
||||||
@@ -626,7 +627,7 @@ export default function App() {
|
|||||||
</div>
|
</div>
|
||||||
<div className="flex gap-2">
|
<div className="flex gap-2">
|
||||||
<a
|
<a
|
||||||
href={`http://192.168.2.117:3001/${doc.file_path}`}
|
href={`${API_HOST}/${doc.file_path}`}
|
||||||
target="_blank"
|
target="_blank"
|
||||||
rel="noopener noreferrer"
|
rel="noopener noreferrer"
|
||||||
className="px-3 py-1 text-sm text-[#0476D9] hover:bg-blue-50 rounded transition-colors border border-[#0476D9]"
|
className="px-3 py-1 text-sm text-[#0476D9] hover:bg-blue-50 rounded transition-colors border border-[#0476D9]"
|
||||||
|
|||||||
@@ -11,6 +11,7 @@
|
|||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"cors": "^2.8.6",
|
"cors": "^2.8.6",
|
||||||
|
"dotenv": "^16.6.1",
|
||||||
"express": "^5.2.1",
|
"express": "^5.2.1",
|
||||||
"multer": "^2.0.2",
|
"multer": "^2.0.2",
|
||||||
"sqlite3": "^5.1.7"
|
"sqlite3": "^5.1.7"
|
||||||
|
|||||||
Reference in New Issue
Block a user