- An action in an encounter no longer loads the encounter again: the answer to the action already holds it. Live updates that arrive together are answered with one reload, of the encounter or character that changed, where each used to reload every one on screen. - Everything the site sends is compressed. Nothing in front of it did that (frp only tunnels), so the API and the built site now do it themselves: the main script is 100 kB on the wire, down from 330 kB. - Each page is its own download, fetched the first time it is opened, so signing in does not wait on the encounter tracker or the builder. - The library is fetched when one of its pickers is opened, where the campaign page used to fetch it on every visit by the DM. - The database has indexes on the columns every list is looked up by, and checking that someone is in a campaign takes one query, not two. - On a server: "npm install", then "npm run deploy", then build the frontend again and restart both. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
44 lines
1.4 KiB
JavaScript
44 lines
1.4 KiB
JavaScript
const express = require('express');
|
|
const cors = require('cors');
|
|
const compression = require('compression');
|
|
|
|
const authRoutes = require('./routes/auth.routes');
|
|
const campaignsRoutes = require('./routes/campaigns.routes');
|
|
const charactersRoutes = require('./routes/characters.routes');
|
|
const encountersRoutes = require('./routes/encounters.routes');
|
|
const notesRoutes = require('./routes/notes.routes');
|
|
|
|
function createApp() {
|
|
const app = express();
|
|
|
|
app.use(cors({ origin: process.env.CORS_ORIGIN || 'http://localhost:5173' }));
|
|
// Nothing in front of the API compresses for it (frp only tunnels), so the
|
|
// JSON is gzipped here.
|
|
app.use(compression());
|
|
app.use(express.json());
|
|
|
|
app.get('/health', (req, res) => res.json({ ok: true }));
|
|
|
|
app.use('/auth', authRoutes);
|
|
app.use('/campaigns', campaignsRoutes);
|
|
app.use('/characters', charactersRoutes);
|
|
app.use('/encounters', encountersRoutes);
|
|
app.use('/notes', notesRoutes);
|
|
|
|
app.use((req, res) => {
|
|
res.status(404).json({ error: 'Not found' });
|
|
});
|
|
|
|
// eslint-disable-next-line no-unused-vars
|
|
app.use((err, req, res, next) => {
|
|
console.error(err);
|
|
if (err.code === 'P2025') return res.status(404).json({ error: 'Record not found' });
|
|
if (err.code === 'P2002') return res.status(409).json({ error: 'A record with that value already exists' });
|
|
res.status(500).json({ error: 'Internal server error' });
|
|
});
|
|
|
|
return app;
|
|
}
|
|
|
|
module.exports = { createApp };
|