forked from snyk-partners/ai-generated-app
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.ts
29 lines (24 loc) · 770 Bytes
/
index.ts
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
import express from 'express';
import multer from 'multer';
import fs from 'fs';
import path from 'path';
export const app = express();
const upload = multer({ dest: 'uploads/' });
app.use(express.static('public'));
app.post('/upload', upload.single('pdf'), (req, res) => {
if (!req.file) {
return res.status(400).send('No file uploaded.');
}
res.send(`File uploaded: ${req.file.filename}`);
});
app.get('/download/:filename', (req, res) => {
const filePath = path.join(__dirname, 'uploads', req.params.filename);
const fileStream = fs.createReadStream(filePath);
fileStream.on('error', () => {
res.status(404).send('File not found');
});
fileStream.pipe(res);
});
app.listen(3000, () => {
console.log('Server listening on port 3000');
});