- Use timing-safe comparisons for HMAC verification and password checks - Add login rate limiting (5 attempts/minute per IP) - Lock down CORS to Vite dev origin only (not needed in production) - Derive signing key from APP_PASSWORD instead of using it directly - Replace hand-rolled cookie parsing with cookie-parser middleware - Wrap all order mutations in SQLite transactions - Fix TOCTOU race on stock with atomic UPDATE...WHERE quantity >= ? - Fix APP_SECERT typo in .env (gitignored, local fix only) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
43 lines
1.3 KiB
JavaScript
43 lines
1.3 KiB
JavaScript
require('dotenv').config({ path: require('path').join(__dirname, '..', '.env') });
|
|
const express = require('express');
|
|
const cookieParser = require('cookie-parser');
|
|
const path = require('path');
|
|
|
|
const authRouter = require('./routes/auth');
|
|
const { authMiddleware } = require('./middleware/auth');
|
|
const productsRouter = require('./routes/products');
|
|
const customersRouter = require('./routes/customers');
|
|
const ordersRouter = require('./routes/orders');
|
|
const dashboardRouter = require('./routes/dashboard');
|
|
|
|
const app = express();
|
|
const PORT = process.env.PORT || 3002;
|
|
|
|
app.set('trust proxy', 1);
|
|
|
|
if (process.env.NODE_ENV !== 'production') {
|
|
const cors = require('cors');
|
|
app.use(cors({ origin: 'http://localhost:5173', credentials: true }));
|
|
}
|
|
|
|
app.use(express.json());
|
|
app.use(cookieParser());
|
|
|
|
app.use('/api/auth', authRouter);
|
|
app.use('/api', authMiddleware);
|
|
app.use('/api/products', productsRouter);
|
|
app.use('/api/customers', customersRouter);
|
|
app.use('/api/orders', ordersRouter);
|
|
app.use('/api/dashboard', dashboardRouter);
|
|
|
|
if (process.env.NODE_ENV === 'production') {
|
|
app.use(express.static(path.join(__dirname, '..', 'client', 'dist')));
|
|
app.get('*', (req, res) => {
|
|
res.sendFile(path.join(__dirname, '..', 'client', 'dist', 'index.html'));
|
|
});
|
|
}
|
|
|
|
app.listen(PORT, () => {
|
|
console.log(`Server running on http://localhost:${PORT}`);
|
|
});
|