Add frontend test component and debug server
This commit is contained in:
@@ -1,10 +1,34 @@
|
||||
require('dotenv').config();
|
||||
const path = require('path');
|
||||
const fs = require('fs');
|
||||
|
||||
// Get the absolute path to the .env file
|
||||
const envPath = path.resolve('/var/www/html/inventory/.env');
|
||||
console.log('Current working directory:', process.cwd());
|
||||
console.log('Looking for .env file at:', envPath);
|
||||
console.log('.env file exists:', fs.existsSync(envPath));
|
||||
|
||||
try {
|
||||
require('dotenv').config({ path: envPath });
|
||||
console.log('.env file loaded successfully');
|
||||
} catch (error) {
|
||||
console.error('Error loading .env file:', error);
|
||||
}
|
||||
|
||||
// Log environment variables (excluding sensitive data)
|
||||
console.log('Environment variables loaded:', {
|
||||
NODE_ENV: process.env.NODE_ENV,
|
||||
PORT: process.env.PORT,
|
||||
DB_HOST: process.env.DB_HOST,
|
||||
DB_USER: process.env.DB_USER,
|
||||
DB_NAME: process.env.DB_NAME,
|
||||
// Not logging DB_PASSWORD for security
|
||||
});
|
||||
|
||||
const express = require('express');
|
||||
const cors = require('cors');
|
||||
const mysql = require('mysql2/promise');
|
||||
const productsRouter = require('./routes/products');
|
||||
const path = require('path');
|
||||
const fs = require('fs');
|
||||
const dashboardRouter = require('./routes/dashboard');
|
||||
|
||||
// Ensure required directories exist
|
||||
['logs', 'uploads'].forEach(dir => {
|
||||
@@ -15,11 +39,14 @@ const fs = require('fs');
|
||||
|
||||
const app = express();
|
||||
|
||||
// Middleware
|
||||
// CORS configuration
|
||||
app.use(cors({
|
||||
origin: process.env.CORS_ORIGIN,
|
||||
origin: ['https://inventory.kent.pw', 'https://www.inventory.kent.pw'],
|
||||
methods: ['GET', 'POST', 'PUT', 'DELETE', 'OPTIONS'],
|
||||
allowedHeaders: ['Content-Type', 'Authorization'],
|
||||
credentials: true
|
||||
}));
|
||||
|
||||
app.use(express.json());
|
||||
|
||||
// Request logging middleware
|
||||
@@ -58,11 +85,12 @@ pool.getConnection()
|
||||
})
|
||||
.catch(err => {
|
||||
console.error('[Database] Error connecting:', err);
|
||||
process.exit(1); // Exit if we can't connect to the database
|
||||
process.exit(1);
|
||||
});
|
||||
|
||||
// Routes
|
||||
app.use('/api/products', productsRouter);
|
||||
app.use('/api/dashboard', dashboardRouter);
|
||||
|
||||
// Basic health check route
|
||||
app.get('/health', (req, res) => {
|
||||
|
||||
Reference in New Issue
Block a user