From 14d5716ca552a539f6b1c6989151c556c23cc28c Mon Sep 17 00:00:00 2001 From: gabriel Date: Sun, 23 Mar 2025 03:01:57 +0100 Subject: [PATCH] qsd --- .env | 2 +- package.json | 3 ++- server/index.js | 20 +++++++++++++++++++ .../20250323010544_autumn_butterfly.sql | 9 ++++++--- vite.config.ts | 10 +++++++++- 5 files changed, 38 insertions(+), 6 deletions(-) diff --git a/.env b/.env index 0ebbd07..75a70cb 100644 --- a/.env +++ b/.env @@ -3,4 +3,4 @@ DB_USER=prox DB_PASSWORD=2104 DB_NAME=prox PORT=3006 -VITE_API_URL=http://localhost:3006/api \ No newline at end of file +VITE_API_URL=/api \ No newline at end of file diff --git a/package.json b/package.json index b0cd0b8..4092a74 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,8 @@ "build": "vite build", "lint": "eslint .", "preview": "vite preview", - "server": "node server/index.js" + "server": "node server/index.js", + "start": "node server/index.js" }, "dependencies": { "axios": "^1.6.7", diff --git a/server/index.js b/server/index.js index 38b9c3b..acb3edd 100644 --- a/server/index.js +++ b/server/index.js @@ -2,13 +2,23 @@ import express from 'express'; import cors from 'cors'; import mysql from 'mysql2/promise'; import dotenv from 'dotenv'; +import path from 'path'; +import { fileURLToPath } from 'url'; +import { webcrypto } from 'crypto'; dotenv.config(); +const __filename = fileURLToPath(import.meta.url); +const __dirname = path.dirname(__filename); +const crypto = webcrypto; + const app = express(); app.use(cors()); app.use(express.json()); +// Serve static files from the dist directory +app.use(express.static(path.join(__dirname, '../dist'))); + const pool = mysql.createPool({ host: process.env.DB_HOST, user: process.env.DB_USER, @@ -27,6 +37,11 @@ pool.getConnection() }) .catch(error => { console.error('Error connecting to the database:', error); + console.error('Connection details:', { + host: process.env.DB_HOST, + user: process.env.DB_USER, + database: process.env.DB_NAME + }); process.exit(1); }); @@ -79,6 +94,11 @@ app.delete('/api/servers/:id', async (req, res) => { } }); +// Serve index.html for all other routes (SPA support) +app.get('*', (req, res) => { + res.sendFile(path.join(__dirname, '../dist/index.html')); +}); + const PORT = process.env.PORT || 3000; app.listen(PORT, () => { console.log(`Server running on port ${PORT}`); diff --git a/supabase/migrations/20250323010544_autumn_butterfly.sql b/supabase/migrations/20250323010544_autumn_butterfly.sql index d83b76e..6dfeb5f 100644 --- a/supabase/migrations/20250323010544_autumn_butterfly.sql +++ b/supabase/migrations/20250323010544_autumn_butterfly.sql @@ -1,6 +1,6 @@ -- Create the database if it doesn't exist -CREATE DATABASE IF NOT EXISTS prox; -USE prox; +CREATE DATABASE IF NOT EXISTS proxmox_dashboard; +USE proxmox_dashboard; -- Create servers table CREATE TABLE IF NOT EXISTS servers ( @@ -18,9 +18,12 @@ CREATE TABLE IF NOT EXISTS servers ( INDEX idx_name (name) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; +-- Create a user for the application (if not exists) +CREATE USER IF NOT EXISTS 'proxmox_user'@'localhost' IDENTIFIED BY 'proxmox_password'; -- Grant privileges to the application user - +GRANT ALL PRIVILEGES ON proxmox_dashboard.* TO 'proxmox_user'@'localhost'; +FLUSH PRIVILEGES; -- Add some sample data (optional) INSERT INTO servers ( diff --git a/vite.config.ts b/vite.config.ts index 147380a..6b3ec2f 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -7,4 +7,12 @@ export default defineConfig({ optimizeDeps: { exclude: ['lucide-react'], }, -}); + server: { + proxy: { + '/api': { + target: 'http://localhost:3006', + changeOrigin: true, + }, + }, + }, +}); \ No newline at end of file