Lee SeJin

Deploy version 1.0

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