-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
86 lines (70 loc) · 1.9 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
const express = require("express")
const mainrouter = require("./routes/main")
const path = require("path")
const app = express()
const db = require("./models")
const multer = require("multer")
const { authJwt } = require("./middleware");
const {User} = require("./models")
// require('./routes/auth.routes')(app);
const bodyParser = require('body-parser');
const cors = require("cors");
const corsOptions = {
origin: ['*', 'http://localhost:3000'],
credentials: true,
optionSuccessStatus: 200,
}
app.use(cors(corsOptions))
const directory = path.resolve(__dirname, 'public', 'assets', 'images')
// const Role=db.roles
// const User=db.User
// function initial() {
// Role.create({
// id: 1,
// name: "user"
// });
// Role.create({
// id: 2,
// name: "moderator"
// });
// Role.create({
// id: 3,
// name: "admin"
// });
// }
const publicdrc = path.resolve(__dirname, 'public')
app.use(express.static(publicdrc))
const storage = multer.diskStorage({
destination: (req, file, cb) => {
cb(null, './public/bloodcertificates')
},
filename: (req, file, cb) => {
cb(null, new Date().toISOString().replace(/:/g, '-') + '-' + file.originalname)
}
})
app.use(bodyParser.json())
const upload = multer({ storage }).single('file');
app.use(mainrouter)
require('./routes/user.routes')(app);
app.post('/upload', [authJwt.verifyToken], (req, res) => {
upload(req, res, (err) => {
if (err) {
return res.status(500).json(err)
}
else{
console.log(req.file.path)
User.update({bloodcertificate: req.file.path},{where:{id:req.userId}}).then((user)=>
{
console.log(user)
}
)
return res.status(200).send(req.file)
}
})
console.log(req.file)
});
db.sequelize.sync().then(req => {
app.listen(process.env.PORT || 5000, () => {
console.log("server running");
})
});