-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
48 lines (36 loc) · 1.09 KB
/
app.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
43
44
45
46
47
48
import express from 'express';
import mongoose from 'mongoose';
import bodyParser from 'body-parser';
import regRouters from './server/routers';
import multer from 'multer';
import path from 'path';
var storage = multer.diskStorage({
destination: function (req, file, cb) {
cb(null, path.resolve('public/uploads'));
},
filename: function (req, file, cb) {
cb(null, Date.now() + path.extname(file.originalname));
}
});
const upload = multer({storage: storage});
const app = express();
mongoose.connect('mongodb://localhost/todos');
app.post('/profile', upload.single('avatar'), (req, res)=> {
res.send({
err: null,
filePath: 'uploads/' + path.basename(req.file.path)
});
});
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ // to support URL-encoded bodies
extended: true
}));
app.use(express.static('public'));
regRouters(app);
app.use('*', (req, res)=> {
res.sendFile(path.resolve('./public/index.html'));
});
app.listen(3000, function() {
console.log('server started at http://localhost:3000'); // eslint-disable-line no-console
});
export default app;