Merge remote-tracking branch 'origin' into feature/frontend-js
Showing
12 changed files
with
52 additions
and
22 deletions
.vscode/settings.json
deleted
100644 → 0
... | @@ -3,8 +3,12 @@ | ... | @@ -3,8 +3,12 @@ |
3 | "version": "1.0.0", | 3 | "version": "1.0.0", |
4 | "description": "2021 OSS Project Using node!", | 4 | "description": "2021 OSS Project Using node!", |
5 | "scripts": { | 5 | "scripts": { |
6 | + "start": "node build/init.js", | ||
7 | + "build": "npm run build:server && npm run build:assets", | ||
8 | + "build:server": "babel src -d build", | ||
9 | + "build:assets": "webpack --mode=production", | ||
6 | "dev:server": "nodemon", | 10 | "dev:server": "nodemon", |
7 | - "dev:assets": "webpack" | 11 | + "dev:assets": "webpack --mode=development -w" |
8 | }, | 12 | }, |
9 | "repository": { | 13 | "repository": { |
10 | "type": "git", | 14 | "type": "git", |
... | @@ -13,9 +17,7 @@ | ... | @@ -13,9 +17,7 @@ |
13 | "author": "Lee SeJin", | 17 | "author": "Lee SeJin", |
14 | "license": "MIT", | 18 | "license": "MIT", |
15 | "dependencies": { | 19 | "dependencies": { |
16 | - "@babel/core": "^7.14.0", | 20 | + "aws-sdk": "^2.922.0", |
17 | - "@babel/node": "^7.13.13", | ||
18 | - "@babel/preset-env": "^7.14.1", | ||
19 | "axios": "^0.21.1", | 21 | "axios": "^0.21.1", |
20 | "connect-mongo": "^4.4.1", | 22 | "connect-mongo": "^4.4.1", |
21 | "dotenv": "^9.0.2", | 23 | "dotenv": "^9.0.2", |
... | @@ -24,13 +26,19 @@ | ... | @@ -24,13 +26,19 @@ |
24 | "mongoose": "^5.12.9", | 26 | "mongoose": "^5.12.9", |
25 | "morgan": "^1.10.0", | 27 | "morgan": "^1.10.0", |
26 | "multer": "^1.4.2", | 28 | "multer": "^1.4.2", |
29 | + "multer-s3": "^2.9.0", | ||
27 | "node-fetch": "^2.6.1", | 30 | "node-fetch": "^2.6.1", |
28 | "nodemon": "^2.0.7", | 31 | "nodemon": "^2.0.7", |
29 | "passport": "^0.4.1", | 32 | "passport": "^0.4.1", |
30 | "passport-github2": "^0.1.12", | 33 | "passport-github2": "^0.1.12", |
31 | - "pug": "^3.0.2" | 34 | + "pug": "^3.0.2", |
35 | + "regenerator-runtime": "^0.13.7" | ||
32 | }, | 36 | }, |
33 | "devDependencies": { | 37 | "devDependencies": { |
38 | + "@babel/core": "^7.14.0", | ||
39 | + "@babel/node": "^7.13.13", | ||
40 | + "@babel/preset-env": "^7.14.1", | ||
41 | + "@babel/cli": "^7.14.3", | ||
34 | "babel-loader": "^8.2.2", | 42 | "babel-loader": "^8.2.2", |
35 | "css-loader": "^5.2.6", | 43 | "css-loader": "^5.2.6", |
36 | "eslint-config-prettier": "^8.3.0", | 44 | "eslint-config-prettier": "^8.3.0", | ... | ... |
... | @@ -29,7 +29,7 @@ export const getUserDetail = async (req, res) => { | ... | @@ -29,7 +29,7 @@ export const getUserDetail = async (req, res) => { |
29 | const user = await User.findById(id); | 29 | const user = await User.findById(id); |
30 | const totalCon = await getContributions(user.githubName); | 30 | const totalCon = await getContributions(user.githubName); |
31 | res.render("userDetail", { | 31 | res.render("userDetail", { |
32 | - pagetTitle: "User Detail", | 32 | + pageTitle: "User Detail", |
33 | quote: quote.quote, | 33 | quote: quote.quote, |
34 | author: quote.author, | 34 | author: quote.author, |
35 | user, | 35 | user, |
... | @@ -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.path : 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, | ... | ... |
1 | +import "regenerator-runtime"; | ||
1 | import "dotenv/config"; | 2 | import "dotenv/config"; |
2 | import "./db"; | 3 | import "./db"; |
3 | import "./models/User"; | 4 | import "./models/User"; |
4 | import app from "./server"; | 5 | import app from "./server"; |
5 | 6 | ||
6 | 7 | ||
7 | -const PORT = 5500; | 8 | +const PORT = process.env.PORT || 5500; |
8 | const handleListening = () => console.log(`✅ Server running : http://localhost:${PORT}`); | 9 | const handleListening = () => console.log(`✅ Server running : http://localhost:${PORT}`); |
9 | 10 | ||
10 | app.listen(PORT, handleListening); | 11 | app.listen(PORT, handleListening); |
... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
1 | import multer from "multer"; | 1 | import multer from "multer"; |
2 | +import multerS3 from "multer-s3"; | ||
3 | +import aws from "aws-sdk"; | ||
4 | + | ||
5 | +const s3 = new aws.S3({ | ||
6 | + credentials: { | ||
7 | + accessKeyId: process.env.AWS_ID, | ||
8 | + secretAccessKey: process.env.AWS_SECRET | ||
9 | + } | ||
10 | +}); | ||
11 | + | ||
12 | +const isHeroku = process.env.NODE_ENV === "production"; | ||
13 | + | ||
14 | +const multerUploader = multerS3({ | ||
15 | + s3: s3, | ||
16 | + bucket: "developer-profile-oss", | ||
17 | + acl: "public-read", | ||
18 | +}) | ||
2 | 19 | ||
3 | export const localsMiddleware = (req,res,next) => { | 20 | export const localsMiddleware = (req,res,next) => { |
4 | res.locals.siteName = "Dev Profile"; | 21 | res.locals.siteName = "Dev Profile"; |
5 | res.locals.loggedUser = req.user || null; | 22 | res.locals.loggedUser = req.user || null; |
6 | - | 23 | + res.locals.isHeroku = isHeroku; |
7 | next(); | 24 | next(); |
8 | }; | 25 | }; |
9 | 26 | ||
... | @@ -27,5 +44,6 @@ export const uploadFiles = multer({ | ... | @@ -27,5 +44,6 @@ export const uploadFiles = multer({ |
27 | dest:"uploads/", | 44 | dest:"uploads/", |
28 | limits: { | 45 | limits: { |
29 | fileSize: 3000000 | 46 | fileSize: 3000000 |
30 | - } | 47 | + }, |
48 | + storage: isHeroku? multerUploader : undefined, | ||
31 | }); | 49 | }); |
... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
... | @@ -7,7 +7,7 @@ passport.use(new GithubStrategy( | ... | @@ -7,7 +7,7 @@ passport.use(new GithubStrategy( |
7 | { | 7 | { |
8 | clientID: process.env.GH_ID, | 8 | clientID: process.env.GH_ID, |
9 | clientSecret: process.env.GH_SECRET, | 9 | clientSecret: process.env.GH_SECRET, |
10 | - callbackURL: `http://localhost:5500/auth/github/callback` | 10 | + callbackURL: `https://dev-profile-2021.herokuapp.com/auth/github/callback` |
11 | }, | 11 | }, |
12 | githubLoginCallback | 12 | githubLoginCallback |
13 | ) | 13 | ) | ... | ... |
... | @@ -14,7 +14,7 @@ const app = express(); | ... | @@ -14,7 +14,7 @@ const app = express(); |
14 | 14 | ||
15 | 15 | ||
16 | app.set("view engine","pug"); | 16 | app.set("view engine","pug"); |
17 | -app.set("views", path.join(__dirname, "views")); | 17 | +app.set("views", process.cwd() + "/src/views"); |
18 | app.use(express.static(path.join(__dirname, "static"))); | 18 | app.use(express.static(path.join(__dirname, "static"))); |
19 | app.use(morgan("dev")); | 19 | app.use(morgan("dev")); |
20 | app.use(express.json()); | 20 | app.use(express.json()); | ... | ... |
... | @@ -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 | ... | ... |
... | @@ -8,8 +8,11 @@ block content | ... | @@ -8,8 +8,11 @@ block content |
8 | hr | 8 | hr |
9 | .pageLayout | 9 | .pageLayout |
10 | .user-profile | 10 | .user-profile |
11 | - .user-profile__column | 11 | + .user-profile__column |
12 | - img(src=`/${user.avatarUrl}`) | 12 | + if isHeroku |
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 | ... | ... |
... | @@ -8,8 +8,6 @@ module.exports = { | ... | @@ -8,8 +8,6 @@ module.exports = { |
8 | githubInfo: "./src/client/js/githubInfo.js", | 8 | githubInfo: "./src/client/js/githubInfo.js", |
9 | search: "./src/client/js/search.js", | 9 | search: "./src/client/js/search.js", |
10 | }, | 10 | }, |
11 | - mode: "development", | ||
12 | - watch: true, | ||
13 | plugins: [ | 11 | plugins: [ |
14 | new MiniCssExtractPlugin({ | 12 | new MiniCssExtractPlugin({ |
15 | filename: "css/styles.css", | 13 | filename: "css/styles.css", | ... | ... |
-
Please register or login to post a comment