middlewares.js
681 Bytes
import multer from "multer";
import routes from "./routes";
const multerVideo = multer({ dest: "uploads/videos/" });
export const localsMiddleware = (req, res, next) => {
res.locals.siteName = "my Youtube";
res.locals.routes = routes;
res.locals.user = req.user || null;
next();
};
export const onlyPublic = (req, res, next) => {
if (req.user) {
res.redirect(routes.home);
} else {
next();
}
};
export const onlyPrivate = (req, res, next) => {
if (req.user) {
next();
} else {
res.redirect(routes.home);
}
};
export const uploadVideo = multerVideo.single("videoFile");
// single에 들어간 videoFile은 upload.pug의 file 부분 input name