IG RINDA YUDA WARDANA#28
Conversation
| @@ -0,0 +1,12 @@ | |||
| { | |||
There was a problem hiding this comment.
Jangan push keyfie.json!
dihapus yaa
| "scripts": { | ||
| "test": "echo \"Error: no test specified\" && exit 1", | ||
| "dev": "nodemon app.js", | ||
| "start": "nodemon app.js" |
There was a problem hiding this comment.
biasanya kalo start, tidak menggunakan nodemon
| @@ -0,0 +1,6 @@ | |||
| PORT=3000 | |||
There was a problem hiding this comment.
valuenya tidak perlu diisi, kasih kosong saja
| @@ -0,0 +1,32 @@ | |||
| if (!process.env.NODE_ENV || process.env.NODE_ENV === "development") { | |||
There was a problem hiding this comment.
padahal di script kamu tidak menggunakan NODE_ENV. jika masih bingung bisa ditanya yaa
| const port = process.env.PORT; | ||
|
|
||
| mongoose.connect( | ||
| "mongodb://localhost:27017/Mini-WP", |
There was a problem hiding this comment.
tips: untuk url bisa dibuat variable tersendiri
| @@ -0,0 +1,10 @@ | |||
| let errHandler = (err, req, res, next) => { | |||
| let code = err.status; | |||
| let message = err.message; | |||
There was a problem hiding this comment.
terkait message, ada beberapa yang biasanya handle lebih umum seperti Internal Server Error. Dan ada beberapa yang bentuknya array, jadi lebih spesifik lagi untuk handlenya ya
| route.use("/users", userR); | ||
| route.use("/articles", articleR); | ||
|
|
||
| route.get("/*", (req, res) => { |
There was a problem hiding this comment.
tips: kamu bisa menggunakan ini untuk check 404 page not found, jadi disesuaikan penggunaannya
| @@ -0,0 +1,13 @@ | |||
| const route = require("express").Router(); | |||
| const userR = require("../routes/userRoutes"); | |||
There was a problem hiding this comment.
kenapa keluar folder terus masuk ke folder lagi yang sama untuk aksesnya?
| route.post("/login/google", userController.loginGoogle); | ||
| route.post("/login", userController.login); | ||
|
|
||
| route.post("/*", (req, res) => { |
| @@ -0,0 +1,24 @@ | |||
| const route = require("express").Router(); | |||
| const articleC = require("../controller/articleController"); | |||
There was a problem hiding this comment.
tips: jika controller, sebaiknya tidak perlu di singkat jadi articleC, route juga
| images.sendUploadToGCS, | ||
| articleC.create | ||
| ); | ||
| route.patch("/article", articleC.update); |
There was a problem hiding this comment.
biasanya patch juga ada proses authorization
| route.patch("/article", articleC.update); | ||
| route.delete("/article/:id", authorization, articleC.delete); | ||
|
|
||
| route.post("/*", (req, res) => { |
| let token = jwt.sign(val, process.env.JWT_SECRET); | ||
| return token; | ||
| }, | ||
| verify: function(val) { |
There was a problem hiding this comment.
untuk melakukan proses verify, sebaiknya menggunakan try catch, bukan if else
| @@ -0,0 +1,54 @@ | |||
| const { verify } = require("../helpers/jwt"); | |||
There was a problem hiding this comment.
tips: nama filenya bisa menggunakan auth
| let token = req.headers.token; | ||
|
|
||
| if (token) { | ||
| let decode = verify(token); |
There was a problem hiding this comment.
gunakan try catch untuk memastikan token menggunakan salt yang sama, nanti errornya masalah signature
| req.user = found; | ||
| next(); | ||
| } else { | ||
| throw { code: 401, message: `Unauthenticate` }; |
There was a problem hiding this comment.
ini errornya: masalah internal server error
| required: [true, " Email required. "], | ||
| validate: [ | ||
| { | ||
| validator: function(value) { |
There was a problem hiding this comment.
tips: akan lebih rapih jika kamu bungkus dalam helper
| title: String, | ||
| userId: String, | ||
| content: String, | ||
| cretedAt: Date, |
There was a problem hiding this comment.
tips: sebenarnya ketika membuat schema, kamu bisa menambahkan option timestamps dan dia memiliki createdat dan updatedat
|
|
||
| let articleSchema = new mongoose.Schema({ | ||
| title: String, | ||
| userId: String, |
There was a problem hiding this comment.
bainya kamu menggunakan ref tehadap user yang kamu gunakan
| <section class="hero is-fullheight"> | ||
| <!-- head --> | ||
| <div class="hero-head"> | ||
| <nav class="navbar"> |
There was a problem hiding this comment.
harusnya bisa dijadikan component
| </div> | ||
| </div> | ||
| <!-- end of Article Page --> | ||
| <!-- GaleryPage --> |
There was a problem hiding this comment.
bisa dijadikan component
| <!-- end of signIn --> | ||
| </div> | ||
| <!-- end of body --> | ||
| <!-- footer --> |
There was a problem hiding this comment.
bisa dijadikan component
| @@ -0,0 +1,340 @@ | |||
| <!DOCTYPE html> | |||
There was a problem hiding this comment.
masih belum menerapkan Single File Component
|
ENV yang saya gunakan :
PORT=3000
JWT_SECRET=helloworld
CLIENT_ID=132166001773-nljl5umc0vmdlvodji12sfl1eqk051q7.apps.googleusercontent.com
GCLOUD_PROJECT=yudawardana-1560407905203
CLOUD_BUCKET=yuda-wardana
KEYFILE_PATH=keyfile.json