Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion backend/routes/email.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
const express = require('express');
const { DEFAULT_RECIPIENTS, sendEmergencyEmail } = require('../services/emailService');
const logger = require('../utils/logger');
const { verifyToken } = require('../middleware/auth');

const router = express.Router();

router.post('/', async (req, res) => {
router.post('/', verifyToken, async (req, res) => {
try {
const report = req?.body?.report;
const recipients = Array.isArray(req?.body?.recipients) ? req.body.recipients : DEFAULT_RECIPIENTS;
Expand Down
11 changes: 11 additions & 0 deletions backend/routes/incidents.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,23 @@ const writeDb = (db) => {
fs.renameSync(tmpPath, DB_PATH);
};

const isValidIncidentId = (id) =>
typeof id === 'string' && id.length > 0 && id.length <= 64;

const findIncident = (db, incidentId) =>
db.incidents.find((i) => i.incidentId === incidentId) || null;

// All incident routes require auth
router.use(verifyToken);

// Validate incidentId parameter format
router.param('incidentId', (req, res, next, id) => {
if (!isValidIncidentId(id)) {
return res.status(400).json({ success: false, error: 'Invalid incidentId format.' });
}
next();
});

/**
* POST /api/incidents/mock
* Creates a mocked incident report record for the authenticated user.
Expand Down
3 changes: 1 addition & 2 deletions backend/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const app = express();
const PORT = process.env.PORT || 5000;

app.use(cors());
app.use(express.json({ limit: '8mb' }));
app.use(express.json({ limit: '1mb' }));

app.use((req, res, next) => {
const startedAt = Date.now();
Expand Down Expand Up @@ -49,7 +49,6 @@ app.use('/api/history', historyRoutes);
app.use('/api/vehicle-observations', vehicleObservationRoutes);
app.use('/api/incidents', incidentRoutes);
app.use('/api/audio', audioRoutes);
app.use(userVideoRoutes);
app.use('/api', userVideoRoutes);

// Supports both:
Expand Down