-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
42 lines (36 loc) · 1.17 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
const express = require('express');
const multer = require('multer');
const path = require('path');
const app = express();
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
// In-memory storage for reports
const reports = [];
// Setup multer for file uploads
const upload = multer({ dest: 'uploads/' });
// Route to submit a crime report
app.post('/api/reports', upload.fields([{ name: 'image' }, { name: 'video' }, { name: 'audio' }]), (req, res) => {
const { reporterName, crimeCategory, crimeDescription, location, date, time } = req.body;
const report = {
reporterName,
crimeCategory,
crimeDescription,
location,
date,
time,
files: req.files
};
reports.push(report);
res.status(200).json({ message: 'Report submitted successfully!' });
});
// Admin login route
app.post('/api/admin', (req, res) => {
const { username, password } = req.body;
if (username === 'admin' && password === 'adminpassword') {
res.status(200).json({ message: 'Login successful', reports });
} else {
res.status(401).json({ message: 'Invalid credentials' });
}
});
// Handle Vercel's serverless function export
module.exports = app;