JungSeungHyun

Merge remote-tracking branch 'origin' into feature/frontend-js

......@@ -120,5 +120,5 @@ dist
package-lock.json
/uploads
/assets
build
/build
.vscode
\ No newline at end of file
......
{
"git.ignoreLimitWarning": true
}
\ No newline at end of file
......@@ -3,8 +3,12 @@
"version": "1.0.0",
"description": "2021 OSS Project Using node!",
"scripts": {
"start": "node build/init.js",
"build": "npm run build:server && npm run build:assets",
"build:server": "babel src -d build",
"build:assets": "webpack --mode=production",
"dev:server": "nodemon",
"dev:assets": "webpack"
"dev:assets": "webpack --mode=development -w"
},
"repository": {
"type": "git",
......@@ -13,9 +17,7 @@
"author": "Lee SeJin",
"license": "MIT",
"dependencies": {
"@babel/core": "^7.14.0",
"@babel/node": "^7.13.13",
"@babel/preset-env": "^7.14.1",
"aws-sdk": "^2.922.0",
"axios": "^0.21.1",
"connect-mongo": "^4.4.1",
"dotenv": "^9.0.2",
......@@ -24,13 +26,19 @@
"mongoose": "^5.12.9",
"morgan": "^1.10.0",
"multer": "^1.4.2",
"multer-s3": "^2.9.0",
"node-fetch": "^2.6.1",
"nodemon": "^2.0.7",
"passport": "^0.4.1",
"passport-github2": "^0.1.12",
"pug": "^3.0.2"
"pug": "^3.0.2",
"regenerator-runtime": "^0.13.7"
},
"devDependencies": {
"@babel/core": "^7.14.0",
"@babel/node": "^7.13.13",
"@babel/preset-env": "^7.14.1",
"@babel/cli": "^7.14.3",
"babel-loader": "^8.2.2",
"css-loader": "^5.2.6",
"eslint-config-prettier": "^8.3.0",
......
import "regenerator-runtime";
import "../scss/styles.scss";
console.log("main");
......
......@@ -29,7 +29,7 @@ export const getUserDetail = async (req, res) => {
const user = await User.findById(id);
const totalCon = await getContributions(user.githubName);
res.render("userDetail", {
pagetTitle: "User Detail",
pageTitle: "User Detail",
quote: quote.quote,
author: quote.author,
user,
......@@ -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.path : req.session.passport.user.avatarUrl,
avatarUrl: file ? (isHeroku ? file.location : file.path) : req.session.passport.user.avatarUrl,
name,
email,
school,
......
import "regenerator-runtime";
import "dotenv/config";
import "./db";
import "./models/User";
import app from "./server";
const PORT = 5500;
const PORT = process.env.PORT || 5500;
const handleListening = () => console.log(`✅ Server running : http://localhost:${PORT}`);
app.listen(PORT, handleListening);
\ No newline at end of file
......
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 isHeroku = process.env.NODE_ENV === "production";
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;
res.locals.isHeroku = isHeroku;
next();
};
......@@ -27,5 +44,6 @@ export const uploadFiles = multer({
dest:"uploads/",
limits: {
fileSize: 3000000
}
},
storage: isHeroku? multerUploader : undefined,
});
\ No newline at end of file
......
......@@ -7,7 +7,7 @@ passport.use(new GithubStrategy(
{
clientID: process.env.GH_ID,
clientSecret: process.env.GH_SECRET,
callbackURL: `http://localhost:5500/auth/github/callback`
callbackURL: `https://dev-profile-2021.herokuapp.com/auth/github/callback`
},
githubLoginCallback
)
......
......@@ -14,7 +14,7 @@ const app = express();
app.set("view engine","pug");
app.set("views", path.join(__dirname, "views"));
app.set("views", process.cwd() + "/src/views");
app.use(express.static(path.join(__dirname, "static")));
app.use(morgan("dev"));
app.use(express.json());
......
......@@ -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
......
......@@ -9,6 +9,9 @@ block content
.pageLayout
.user-profile
.user-profile__column
if isHeroku
img(src=`${user.avatarUrl}`)
else
img(src=`/${user.avatarUrl}`)
.user-profile__link
a(href=user.githubUrl target="_blank") GitHub
......
......@@ -8,8 +8,6 @@ module.exports = {
githubInfo: "./src/client/js/githubInfo.js",
search: "./src/client/js/search.js",
},
mode: "development",
watch: true,
plugins: [
new MiniCssExtractPlugin({
filename: "css/styles.css",
......