Spaces:
Sleeping
Sleeping
File size: 1,039 Bytes
63caaa6 |
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 |
const express = require('express');
const multer = require('multer');
const path = require('path');
const fs = require('fs');
const app = express();
const indexRouter = require('./routes/index');
// Set up view engine
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'pug');
// Set up static files
app.use(express.static(path.join(__dirname, 'public')));
app.use('/data', express.static(path.join(__dirname, 'data'))); // Add this line
// Set up multer for file uploads
const storage = multer.diskStorage({
destination: (req, file, cb) => {
cb(null, 'data/');
},
filename: (req, file, cb) => {
cb(null, file.fieldname + '-' + Date.now() + path.extname(file.originalname));
}
});
const upload = multer({ storage: storage });
// Routes
app.use('/', indexRouter);
app.post('/upload', upload.single('image'), (req, res) => {
res.redirect('/');
});
// Start server
const port = process.env.PORT || 3000;
app.listen(port, () => {
console.log(`Server running on port ${port}`);
});
module.exports = app; |