qsd
This commit is contained in:
parent
c081c62b65
commit
14d5716ca5
5 changed files with 38 additions and 6 deletions
2
.env
2
.env
|
@ -3,4 +3,4 @@ DB_USER=prox
|
|||
DB_PASSWORD=2104
|
||||
DB_NAME=prox
|
||||
PORT=3006
|
||||
VITE_API_URL=http://localhost:3006/api
|
||||
VITE_API_URL=/api
|
|
@ -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",
|
||||
|
|
|
@ -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}`);
|
||||
|
|
|
@ -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 (
|
||||
|
|
|
@ -7,4 +7,12 @@ export default defineConfig({
|
|||
optimizeDeps: {
|
||||
exclude: ['lucide-react'],
|
||||
},
|
||||
});
|
||||
server: {
|
||||
proxy: {
|
||||
'/api': {
|
||||
target: 'http://localhost:3006',
|
||||
changeOrigin: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
Loading…
Reference in a new issue