-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
31 lines (24 loc) · 1.06 KB
/
server.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
const express = require('express');
const mongoose = require('mongoose');
const UserStatus = require('./db/db');
const {upload}=require('./middlewares/upload');
require('dotenv').config();
const app = express();
// Connect to MongoDB
mongoose.connect(process.env.MONGO_URL)
.then(() => console.log('MongoDB connected'))
.catch(err => console.error('MongoDB connection error:', err));
// Upload status route
app.post('/upload-status', upload.single('status'), async (req, res) => {
try {
const userId = req.body.userId; // You can get from the token in authorization headers or give it random manually
const statusContent = req.file.location //Your Image or the Video Status
const newStatus = new UserStatus({ userId, statusContent });
await newStatus.save();
res.status(200).json({ message: 'Status uploaded successfully' });
} catch (err) {
console.error(err);
res.status(500).json({ message: 'Error uploading status' });
}
});
app.listen(process.env.PORT, () => console.log('Server started on port 3000'));