fix build issues for pi

was reverting back to old monolithic index, now points to modular build
pull/20/head
accius 3 days ago
parent 13491d95fe
commit 56ef669ad2

@ -9,6 +9,7 @@ All notable changes to OpenHamClock will be documented in this file.
- `.env` is auto-created from `.env.example` on first run
- Settings won't be overwritten by git updates
- Supports: CALLSIGN, LOCATOR, PORT, HOST, UNITS, TIME_FORMAT, THEME, LAYOUT
- **Auto-build on start** - `npm start` automatically builds the React frontend if needed
- **Update script** - Easy updates for local/Pi installations (`./scripts/update.sh`)
- Backs up config, pulls latest, rebuilds, preserves settings
- **Network access configuration** - Set `HOST=0.0.0.0` to access from other devices

@ -8,7 +8,7 @@ A modern, modular amateur radio dashboard built with React and Vite. This is the
# Install dependencies
npm install
# Start the server (auto-creates .env on first run)
# Start the server (auto-builds frontend and creates .env on first run)
npm start
# Edit .env with your callsign and grid locator
@ -18,14 +18,17 @@ npm start
# Open http://localhost:3000
```
**That's it!** On first run, the server automatically creates a `.env` file from `.env.example`. Just edit it with your callsign and locator.
**That's it!** On first run:
- Frontend is automatically built (React app compiled to `dist/`)
- `.env` file is created from `.env.example`
- Just edit `.env` with your callsign and locator
For development with hot reload:
```bash
# Terminal 1: Backend API server
node server.js
# Terminal 2: Frontend dev server
# Terminal 2: Frontend dev server with hot reload
npm run dev
```

@ -1,12 +1,13 @@
{
"name": "openhamclock",
"version": "3.7.0",
"version": "3.10.0",
"description": "Amateur Radio Dashboard - A modern web-based HamClock alternative",
"main": "server.js",
"scripts": {
"dev": "vite",
"build": "vite build",
"preview": "vite preview",
"prestart": "node -e \"const fs=require('fs'); if(!fs.existsSync('dist/index.html')){console.log('Building frontend...'); require('child_process').execSync('npm run build',{stdio:'inherit'})}\"",
"start": "node server.js",
"server": "node server.js",
"test": "echo \"Tests passing\" && exit 0"

@ -0,0 +1,82 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>OpenHamClock - Build Required</title>
<style>
* { margin: 0; padding: 0; box-sizing: border-box; }
body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
background: #1a1a2e;
color: #eee;
min-height: 100vh;
display: flex;
align-items: center;
justify-content: center;
}
.container {
text-align: center;
padding: 40px;
max-width: 600px;
}
h1 {
color: #fbbf24;
font-size: 2.5rem;
margin-bottom: 20px;
}
p {
font-size: 1.1rem;
line-height: 1.6;
margin-bottom: 15px;
color: #aaa;
}
code {
background: #2d2d44;
padding: 4px 10px;
border-radius: 4px;
font-family: 'JetBrains Mono', monospace;
color: #4ade80;
}
.command {
background: #2d2d44;
padding: 20px;
border-radius: 8px;
margin: 30px 0;
text-align: left;
}
.command code {
display: block;
background: none;
padding: 5px 0;
}
.note {
font-size: 0.9rem;
color: #888;
margin-top: 30px;
}
</style>
</head>
<body>
<div class="container">
<h1>📻 OpenHamClock</h1>
<p>The frontend needs to be built before running.</p>
<div class="command">
<code>npm install</code>
<code>npm run build</code>
<code>npm start</code>
</div>
<p>Or use the quick start:</p>
<div class="command">
<code>npm install && npm start</code>
</div>
<p class="note">
If you're seeing this page, the build step was skipped.<br>
Running <code>npm start</code> should auto-build if needed.
</p>
</div>
</body>
</html>

@ -192,17 +192,27 @@ function logErrorOnce(category, message) {
return false;
}
// Serve static files - use 'dist' in production (Vite build), 'public' in development
const staticDir = process.env.NODE_ENV === 'production'
? path.join(__dirname, 'dist')
: path.join(__dirname, 'public');
app.use(express.static(staticDir));
// Also serve public folder for any additional assets
if (process.env.NODE_ENV === 'production') {
app.use(express.static(path.join(__dirname, 'public')));
// Serve static files
// dist/ contains the built React app (from npm run build)
// public/ contains the fallback page if build hasn't run
const distDir = path.join(__dirname, 'dist');
const publicDir = path.join(__dirname, 'public');
// Check if dist/ exists (has index.html from build)
const distExists = fs.existsSync(path.join(distDir, 'index.html'));
if (distExists) {
// Serve built React app from dist/
app.use(express.static(distDir));
console.log('[Server] Serving React app from dist/');
} else {
// No build found - serve placeholder from public/
console.log('[Server] ⚠️ No build found! Run: npm run build');
}
// Always serve public folder (for fallback and assets)
app.use(express.static(publicDir));
// ============================================
// API PROXY ENDPOINTS
// ============================================
@ -3083,9 +3093,11 @@ app.get('/api/config', (req, res) => {
// ============================================
app.get('*', (req, res) => {
const indexPath = process.env.NODE_ENV === 'production'
? path.join(__dirname, 'dist', 'index.html')
: path.join(__dirname, 'public', 'index.html');
// Try dist first (built React app), fallback to public (monolithic)
const distIndex = path.join(__dirname, 'dist', 'index.html');
const publicIndex = path.join(__dirname, 'public', 'index.html');
const indexPath = fs.existsSync(distIndex) ? distIndex : publicIndex;
res.sendFile(indexPath);
});

Loading…
Cancel
Save

Powered by TurnKey Linux.