sitespeed.io web UI with Express/Pug/SQLite — port 3132. Includes job queue, SSE live log, full metrics dashboard, site history, CO2/axe/CWV sections, and Docker support. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
55 lines
1.4 KiB
JavaScript
55 lines
1.4 KiB
JavaScript
import express from 'express';
|
|
import { join, dirname } from 'path';
|
|
import { fileURLToPath } from 'url';
|
|
import { getDb } from './db.js';
|
|
|
|
// Routes
|
|
import indexRouter from './routes/index.js';
|
|
import testRouter from './routes/test.js';
|
|
import statusRouter from './routes/status.js';
|
|
import resultsRouter from './routes/results.js';
|
|
import historyRouter from './routes/history.js';
|
|
import siteRouter from './routes/site.js';
|
|
|
|
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
|
|
const app = express();
|
|
const PORT = process.env.PORT || 3132;
|
|
|
|
// Initialize DB on startup
|
|
getDb();
|
|
|
|
// View engine
|
|
app.set('views', join(__dirname, 'views'));
|
|
app.set('view engine', 'pug');
|
|
|
|
// Middleware
|
|
app.use(express.urlencoded({ extended: true }));
|
|
app.use(express.json());
|
|
|
|
// Static reports
|
|
app.use('/reports', express.static(join(__dirname, 'reports')));
|
|
|
|
// Routes
|
|
app.use('/', indexRouter);
|
|
app.use('/test', testRouter);
|
|
app.use('/status', statusRouter);
|
|
app.use('/results', resultsRouter);
|
|
app.use('/history', historyRouter);
|
|
app.use('/site', siteRouter);
|
|
|
|
// 404
|
|
app.use((req, res) => {
|
|
res.status(404).render('error', { title: '404 Not Found', message: 'Page not found.' });
|
|
});
|
|
|
|
// Error handler
|
|
app.use((err, req, res, _next) => {
|
|
console.error(err);
|
|
res.status(500).render('error', { title: 'Server Error', message: err.message });
|
|
});
|
|
|
|
app.listen(PORT, () => {
|
|
console.log(`Speedboard running at http://localhost:${PORT}`);
|
|
});
|