Skip to content

IG RINDA YUDA WARDANA#28

Open
Yudawardana94 wants to merge 10 commits into
eager-fox-2019:masterfrom
Yudawardana94:master
Open

IG RINDA YUDA WARDANA#28
Yudawardana94 wants to merge 10 commits into
eager-fox-2019:masterfrom
Yudawardana94:master

Conversation

@Yudawardana94
Copy link
Copy Markdown

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

Comment thread server/keyfile.json Outdated
@@ -0,0 +1,12 @@
{
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Jangan push keyfie.json!
dihapus yaa

Comment thread server/package.json
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"dev": "nodemon app.js",
"start": "nodemon app.js"
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

biasanya kalo start, tidak menggunakan nodemon

Comment thread server/envExample
@@ -0,0 +1,6 @@
PORT=3000
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

valuenya tidak perlu diisi, kasih kosong saja

Comment thread server/app.js
@@ -0,0 +1,32 @@
if (!process.env.NODE_ENV || process.env.NODE_ENV === "development") {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

padahal di script kamu tidak menggunakan NODE_ENV. jika masih bingung bisa ditanya yaa

Comment thread server/app.js
const port = process.env.PORT;

mongoose.connect(
"mongodb://localhost:27017/Mini-WP",
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Comment thread server/routes/index.js
route.use("/users", userR);
route.use("/articles", articleR);

route.get("/*", (req, res) => {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tips: kamu bisa menggunakan ini untuk check 404 page not found, jadi disesuaikan penggunaannya

Comment thread server/routes/index.js
@@ -0,0 +1,13 @@
const route = require("express").Router();
const userR = require("../routes/userRoutes");
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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) => {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ini untuk apa ya?

@@ -0,0 +1,24 @@
const route = require("express").Router();
const articleC = require("../controller/articleController");
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tips: jika controller, sebaiknya tidak perlu di singkat jadi articleC, route juga

images.sendUploadToGCS,
articleC.create
);
route.patch("/article", articleC.update);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

biasanya patch juga ada proses authorization

route.patch("/article", articleC.update);
route.delete("/article/:id", authorization, articleC.delete);

route.post("/*", (req, res) => {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

kenapa ada ini ya?

Comment thread server/helpers/jwt.js
let token = jwt.sign(val, process.env.JWT_SECRET);
return token;
},
verify: function(val) {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

untuk melakukan proses verify, sebaiknya menggunakan try catch, bukan if else

@@ -0,0 +1,54 @@
const { verify } = require("../helpers/jwt");
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tips: nama filenya bisa menggunakan auth

let token = req.headers.token;

if (token) {
let decode = verify(token);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

gunakan try catch untuk memastikan token menggunakan salt yang sama, nanti errornya masalah signature

req.user = found;
next();
} else {
throw { code: 401, message: `Unauthenticate` };
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ini errornya: masalah internal server error

required: [true, " Email required. "],
validate: [
{
validator: function(value) {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tips: akan lebih rapih jika kamu bungkus dalam helper

title: String,
userId: String,
content: String,
cretedAt: Date,
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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,
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bainya kamu menggunakan ref tehadap user yang kamu gunakan

Comment thread client/index.html
<section class="hero is-fullheight">
<!-- head -->
<div class="hero-head">
<nav class="navbar">
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

harusnya bisa dijadikan component

Comment thread client/index.html
</div>
</div>
<!-- end of Article Page -->
<!-- GaleryPage -->
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bisa dijadikan component

Comment thread client/index.html
<!-- end of signIn -->
</div>
<!-- end of body -->
<!-- footer -->
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bisa dijadikan component

Comment thread client/index.html
@@ -0,0 +1,340 @@
<!DOCTYPE html>
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

masih belum menerapkan Single File Component

@WikaSilo
Copy link
Copy Markdown
Collaborator

  • Jangan push file credential seperti keyfile.json
  • Penamaan variable sebaiknya jangan articleC, articleR, articleM. Lebih detail saja.
  • Client belum dijadikan single file component

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants