middlewares.js
901 Bytes
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
import multer from "multer";
import multerS3 from "multer-s3";
import aws from "aws-sdk";
const s3 = new aws.S3({
credentials: {
accessKeyId: process.env.AWS_ID,
secretAccessKey: process.env.AWS_SECRET
}
});
const multerUploader = multerS3({
s3: s3,
bucket: "developer-profile-oss",
acl: "public-read",
})
export const localsMiddleware = (req,res,next) => {
res.locals.siteName = "Dev Profile";
res.locals.loggedUser = req.user || null;
next();
};
export const onlyPublic = (req, res, next) => {
if(req.user){
res.redirect("/");
} else {
next();
}
};
export const onlyPrivate = (req, res, next) => {
if(req.user){
next();
} else {
res.redirect("/");
}
};
export const uploadFiles = multer({
dest:"uploads/",
limits: {
fileSize: 3000000
},
storage: multerUploader
});