Lee SeJin

Deploy version 1.0

......@@ -63,11 +63,12 @@ export const postEditProfile = async (req, res) => {
body: { name, email, school, blogUrl, tech, career, introduction },
file,
} = req;
const isHeroku = process.env.NODE_ENV === "production";
try {
const updatedUser = await User.findByIdAndUpdate(
id,
{
avatarUrl: file ? file.location : req.session.passport.user.avatarUrl,
avatarUrl: file ? (isHeroku ? file.location : file.path) : req.session.passport.user.avatarUrl,
name,
email,
school,
......
......@@ -9,6 +9,8 @@ const s3 = new aws.S3({
}
});
const isHeroku = process.env.NODE_ENV === "production";
const multerUploader = multerS3({
s3: s3,
bucket: "developer-profile-oss",
......@@ -18,7 +20,7 @@ const multerUploader = multerS3({
export const localsMiddleware = (req,res,next) => {
res.locals.siteName = "Dev Profile";
res.locals.loggedUser = req.user || null;
res.locals.isHeroku = isHeroku;
next();
};
......@@ -43,5 +45,5 @@ export const uploadFiles = multer({
limits: {
fileSize: 3000000
},
storage: multerUploader
storage: isHeroku? multerUploader : undefined,
});
\ No newline at end of file
......
......@@ -3,7 +3,10 @@ extends layouts/main
block content
.form-container
form(action="/users/edit-profile", method="POST", enctype="multipart/form-data")
img(src=`${loggedUser.avatarUrl}`)
if isHeroku
img(src=`${user.avatarUrl}`)
else
img(src=`/${user.avatarUrl}`)
.fileUpload
input(type="file", id="photo", name="photo", accept="image/*")
label(for="photo") Photo
......
......@@ -8,8 +8,11 @@ block content
hr
.pageLayout
.user-profile
.user-profile__column
img(src=`${user.avatarUrl}`)
.user-profile__column
if isHeroku
img(src=`${user.avatarUrl}`)
else
img(src=`/${user.avatarUrl}`)
.user-profile__link
a(href=user.githubUrl target="_blank") GitHub
i.fab.fa-github
......