From b26cb2dd58397d2a6ae9eb23df640d4f771d6627 Mon Sep 17 00:00:00 2001 From: boghdady Date: 2022年3月27日 01:35:45 +0200 Subject: [PATCH 1/9] All Source code --- models/orderModel.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/models/orderModel.js b/models/orderModel.js index 43eb742..1dba1f7 100644 --- a/models/orderModel.js +++ b/models/orderModel.js @@ -69,5 +69,3 @@ orderSchema.pre(/^find/, function (next) { module.exports = mongoose.model('Order', orderSchema); -// In@in2016 -//progahmedelsayed@gmail.com From e1e936375136376a6da720e6a4a53126dc8c303a Mon Sep 17 00:00:00 2001 From: Ahmed Boghdady Date: Fri, 1 Apr 2022 13:17:58 +0200 Subject: [PATCH 2/9] Create README.md --- README.md | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..f597524 --- /dev/null +++ b/README.md @@ -0,0 +1,29 @@ +# Course Material and FAQ for my NodeJS - Build a Full E-Commerce RESTful APIs (بالعربي) + +This repo contains starter files and the finished project files for all the projects contained in the course (complete repo size is **288MB**). + +Use starter code to start each section, and **final code to compare it with your own code whenever something doesn't work**! + + +👇 **_Please read the following Frequently Asked Questions (FAQ) carefully before starting the course_** 👇 + +## FAQ + +### Q1: How do I download the files? + +**A:** If you're new to GitHub and just want to download the entire code, hit the green button saying "Code", and then choose the "Download ZIP" option. + + +### Q2: I'm stuck in one of the projects. Where do I get help? + +**A:** Have you actually tried to fix the problem on your own? Have you compared your code to the final code? If you failed fixing your problem, please **post a detailed description of the problem to the Q&A area of that video over at Udemy**, along with a [codepen](https://codepen.io/pen/) containing your code. You will get help there. Please don't send me a personal message or email to fix coding problems. + + +### Q3: I want to put the project in my portfolio. Is that allowed? + +**A:** Absolutely! Just make sure you actually built it yourself by following the course, and that you understand what you did. What is **not allowed** is that you create your own course/videos/articles based on this course's content! + + +### Q4: Do you accept pull requests? + +**A:** No, for the simple reason that I want this repository to contain the _exact_ same code that is shown in the videos. However, please feel free to add an issue if you found one. From 6b5bdbcdf92e96d27e41f6ecaf2cfbde7905a2a6 Mon Sep 17 00:00:00 2001 From: Ahmed Boghdady Date: Fri, 1 Apr 2022 13:18:49 +0200 Subject: [PATCH 3/9] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index f597524..267a104 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Course Material and FAQ for my NodeJS - Build a Full E-Commerce RESTful APIs (بالعربي) -This repo contains starter files and the finished project files for all the projects contained in the course (complete repo size is **288MB**). +This repo contains starter files and the finished project files for all the projects contained in the course Use starter code to start each section, and **final code to compare it with your own code whenever something doesn't work**! From 47c52818e39e854a109901490b814a9e40d3fc95 Mon Sep 17 00:00:00 2001 From: Ahmed Boghdady Date: Fri, 1 Apr 2022 13:21:33 +0200 Subject: [PATCH 4/9] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 267a104..ff7e21b 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,8 @@ # Course Material and FAQ for my NodeJS - Build a Full E-Commerce RESTful APIs (بالعربي) -This repo contains starter files and the finished project files for all the projects contained in the course +This repo contains every course section in branche and the finished project files for all the projects contained in the master branch -Use starter code to start each section, and **final code to compare it with your own code whenever something doesn't work**! +Choose the section branch that you study, and **final code to compare it with your own code whenever something doesn't work**! 👇 **_Please read the following Frequently Asked Questions (FAQ) carefully before starting the course_** 👇 From 220fbc8c72fc390e1cf685b932feb2b948c61757 Mon Sep 17 00:00:00 2001 From: Ahmed Boghdady Date: Fri, 1 Apr 2022 13:22:17 +0200 Subject: [PATCH 5/9] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index ff7e21b..9a7cb88 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Course Material and FAQ for my NodeJS - Build a Full E-Commerce RESTful APIs (بالعربي) -This repo contains every course section in branche and the finished project files for all the projects contained in the master branch +This repo contains every course section in a single branch and the finished project files for all the projects contained in the master branch Choose the section branch that you study, and **final code to compare it with your own code whenever something doesn't work**! From b12ee5a2a479fcbb1ed88cd489dec48fc4a95187 Mon Sep 17 00:00:00 2001 From: Ahmed Boghdady Date: Fri, 1 Apr 2022 14:06:12 +0200 Subject: [PATCH 6/9] Update README.md --- README.md | 69 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) diff --git a/README.md b/README.md index 9a7cb88..e935c72 100644 --- a/README.md +++ b/README.md @@ -27,3 +27,72 @@ Choose the section branch that you study, and **final code to compare it with yo ### Q4: Do you accept pull requests? **A:** No, for the simple reason that I want this repository to contain the _exact_ same code that is shown in the videos. However, please feel free to add an issue if you found one. + + +## Course Highlights + +Project Overview + +خلال هذا القسم هيتم استعراض مشروع المتجر الإلكتروني اللي هيتم تنفيذه خلال هذا الكورس ... مهم جدا تتفرج عليه بتركيز عشان تكون عارف ايه المميزات اللي هتتنفذ خلال المشروع ده + +How Web Work + +خلال القسم ده هنتكلم شويه عن اساسيات النتورك وازاي الويب بيشتغل عشان كله يكون عنده الاساسيات اللي هنبني عليها اللي جاي وفي نفس الوقت نكون عارف احنا مكانا فين بالظبط وايه دورنا واحنا بنكتب كود + +Preparing Tools And Environment + +خلال القسم ده هنبدأ نجهز بيئة العمل بتاعتنا والمحرر اللي هنبدأ نشتغل عليه + +Preparing Express Server And Mongodb + +خلال القسم ده هنبدأ نجهز الاكسبريس اب بتاعنا ونبدأ ننشأ السيرفر ونربط التطبيق بتاعنا بالداتا بيز وكمان هنشرح الستراكشر بتاع الملفات اللي هنشتغل بيه خلال المشروع اللي هننفذه + +Categories CRUD Operations + +خلال القسم ده هنبدأ التنفيذ الفعل لفيتشر الاقسام داخل المتجر الالكتروني الاقسام دي ممكن تكون ملابس او الكترونيات ..إلى آخره. + +Advanced Error Handling & Adding Validation Layer + +من السكاشن المهمة جدا اللي هنشرح فيها ازاي اكسبريس بيتعامل مع الايرورز وهنبدأ نشوف ازاي نمسك الايرورز دي ونتحكم في شكلها والشكل النهائي اللي هيرجع للمستخدم وكمان هنشوف ازاي نمسك باقي الايرورز اللي ممكن تحصل في باقي التطبيق غير اكسبريس + +SubCategories CRUD & Brands CRUD Operations + +خلال القسم ده هنبدأ ننفذ الاقسام الفرعية اللي هتكون بتنتمي للاقسام الرئيسية بمعني ان القسم الرئيسي ينتمي ليه قسم او اكثر فرعي .. بالاضافه للعمل علي فيشتر البراندات + +Products CRUD Operations + +خلال القسم ده هنبدأ نشتغل علي فيتشر المنتج وهنشوف ازاي نعمل انشاء وتعديل وحذف للمنتج .. بالاضافة ازاي نعمل بحث وازاي نعمل ترتيب للمنتج سواء بسعره او عدد المبيعات للمنتج او غيره .. ازاي كمان نعمل فلتر للمنتج سواء بالقسم اللي بينتمي ليه واو العلامة التجارية وغيره + +Upload Single And Multiple Images And Image Processing + +خلال القسم ده هنشوف ازاي نعمل رفع لصوره واحدة او اكتر من صورة .. وهنشوف ازاي نحسن من العمليات اللي هتم علي الصورة عشان يحسن من الاداء .. وهنتعامل مع الايرورز اللي ممكن تظهرك لما ترفع فايل غير الصور .. وهنبدأ نضيف الصور للمنتج بتاعنا + +Authentication And Authorization + +خلال القسم ده هنشرح عمليه المصادقة بشكل تفصيلي وهنشوف ازاي تسجيل الدخول وانشاء الحساب ونسيت كلمه المرور وازاي بتعمل التوكن وازاي بنعمل عمليه التحقق عليه ..كمان هنشتغل علي صلاحيات المستخدمين وهيكون عندنا ادمن ومانجر ويوزر عادي وكل واحد ليه صلاحيات مختلفة عن التاني... القسم ده مهم جدا وهتستفاد منه جدا + +Reviews, Wishlist And User Addresses + +خلال القسم ده هنبدأ نشتغل علي التقييمات وهنشوف ازاي هنمكن المتسخدم انه يضيف تقييم علي المنتجات وكمان هنحسب متوسط عدد التقييمات علي المنتج الواحد بالاضافة للعدد الكلي للتقيمات علي المنتج الواحد ، كمان هنشرح ازاي نمكن المسخدم انه يضيف منتج لقائمة المفضلة وفي نفس الوقت يقدر يحذفه ، كمان هنمكن المستخدم من انه يضيف عنوان لدفتر العناوين بتاعه يقدر يستخدمه لما يجي يطلب اوردر . + +Coupons And Shopping Cart + +خلال القسم ده هنبدأ نمكن الادمن من انه ينشأ الكوبونات وكل كوبون بيكون ليه تاريخ معين ينتهي فيه ونسبة خصم معينة بيحددها الادمن ... والمستخدم هيقدر يستخدم الكوبون ده عشان يتسفاد من الخصم .. كمان هنمكن المستخدم من انه ينشأ سلة المنتجات اللي هيبدأ يضيف فيها المنتجات اللي عايز يشتريها ويعدل يختار ويعدل في كمية المنتجات لو متاح كمية منها في المخزن بالاضافة انه يقدر يضيف كوبون خصم علي السلة . + +Cash And Online Orders, Online Payments And Deployments + +خلال القسم ده هنبدأ نشتغل علي الاورد ر او الطلبية سواء الاوردر ده هيتم دفعه كاش او عند الاستلام او الاوردر ده هيتم دفعه من خلال بطاقة دفع او محفظة الكترنية زي ابل باي او غيره .. هيتم الربط مع بوابة الدفع ونشوف ايه وسائل الدفع اللي بتوفرها بوابة الدفع وهنعمل عميلة الدفع من خلالها ... وهنشوف ازاي بنشوف عملية الدفع نجحت ولا لا .. وازاي نعمل اوردر في حالة نجاح عملية الدفع .. هنتكلم بالتفصيل عن الدفع الكاش والدفع الالكتروني .. وفي الاخر هنرفع التطبيق علي هيروكو عشان تقدر تشاركه مع الفرونت اند او تحط اللينك في البرورتفوليو بتاعك + +Security + +خلال القسم ده هنتكلم شويه عن وسائل الامان اللي ممكن تستخدمها عشان تأمن التطبيق بتاعك + +Enhancements + +خلال القسم ده هنضيف فيه التحسينات اللي هتتضاف في الكورس ... بالاضافة لو فيه مشاكل ظهرت هنسجلها فيديو ونضيفه في السكشن ده + +Appendix + +خلال القسم ده هضفلكم شويه دروس عن الجافا سكريبت عشان ترجعو ليها لو عايز تتاسس فيها عشان تساعدك وانت شغال في الكورس + + From db4de4c8c2c07e2f9b309d47586a923020ca4c86 Mon Sep 17 00:00:00 2001 From: Ahmed Boghdady Date: Fri, 1 Apr 2022 14:08:35 +0200 Subject: [PATCH 7/9] Update README.md --- README.md | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index e935c72..21ce3b8 100644 --- a/README.md +++ b/README.md @@ -31,67 +31,67 @@ Choose the section branch that you study, and **final code to compare it with yo ## Course Highlights -Project Overview +1- Project Overview خلال هذا القسم هيتم استعراض مشروع المتجر الإلكتروني اللي هيتم تنفيذه خلال هذا الكورس ... مهم جدا تتفرج عليه بتركيز عشان تكون عارف ايه المميزات اللي هتتنفذ خلال المشروع ده -How Web Work +2- How Web Work خلال القسم ده هنتكلم شويه عن اساسيات النتورك وازاي الويب بيشتغل عشان كله يكون عنده الاساسيات اللي هنبني عليها اللي جاي وفي نفس الوقت نكون عارف احنا مكانا فين بالظبط وايه دورنا واحنا بنكتب كود -Preparing Tools And Environment +3- Preparing Tools And Environment خلال القسم ده هنبدأ نجهز بيئة العمل بتاعتنا والمحرر اللي هنبدأ نشتغل عليه -Preparing Express Server And Mongodb +4- Preparing Express Server And Mongodb خلال القسم ده هنبدأ نجهز الاكسبريس اب بتاعنا ونبدأ ننشأ السيرفر ونربط التطبيق بتاعنا بالداتا بيز وكمان هنشرح الستراكشر بتاع الملفات اللي هنشتغل بيه خلال المشروع اللي هننفذه -Categories CRUD Operations +5- Categories CRUD Operations خلال القسم ده هنبدأ التنفيذ الفعل لفيتشر الاقسام داخل المتجر الالكتروني الاقسام دي ممكن تكون ملابس او الكترونيات ..إلى آخره. -Advanced Error Handling & Adding Validation Layer +6- Advanced Error Handling & Adding Validation Layer من السكاشن المهمة جدا اللي هنشرح فيها ازاي اكسبريس بيتعامل مع الايرورز وهنبدأ نشوف ازاي نمسك الايرورز دي ونتحكم في شكلها والشكل النهائي اللي هيرجع للمستخدم وكمان هنشوف ازاي نمسك باقي الايرورز اللي ممكن تحصل في باقي التطبيق غير اكسبريس -SubCategories CRUD & Brands CRUD Operations +7- SubCategories CRUD & Brands CRUD Operations خلال القسم ده هنبدأ ننفذ الاقسام الفرعية اللي هتكون بتنتمي للاقسام الرئيسية بمعني ان القسم الرئيسي ينتمي ليه قسم او اكثر فرعي .. بالاضافه للعمل علي فيشتر البراندات -Products CRUD Operations +8- Products CRUD Operations خلال القسم ده هنبدأ نشتغل علي فيتشر المنتج وهنشوف ازاي نعمل انشاء وتعديل وحذف للمنتج .. بالاضافة ازاي نعمل بحث وازاي نعمل ترتيب للمنتج سواء بسعره او عدد المبيعات للمنتج او غيره .. ازاي كمان نعمل فلتر للمنتج سواء بالقسم اللي بينتمي ليه واو العلامة التجارية وغيره -Upload Single And Multiple Images And Image Processing +9- Upload Single And Multiple Images And Image Processing خلال القسم ده هنشوف ازاي نعمل رفع لصوره واحدة او اكتر من صورة .. وهنشوف ازاي نحسن من العمليات اللي هتم علي الصورة عشان يحسن من الاداء .. وهنتعامل مع الايرورز اللي ممكن تظهرك لما ترفع فايل غير الصور .. وهنبدأ نضيف الصور للمنتج بتاعنا -Authentication And Authorization +10- Authentication And Authorization خلال القسم ده هنشرح عمليه المصادقة بشكل تفصيلي وهنشوف ازاي تسجيل الدخول وانشاء الحساب ونسيت كلمه المرور وازاي بتعمل التوكن وازاي بنعمل عمليه التحقق عليه ..كمان هنشتغل علي صلاحيات المستخدمين وهيكون عندنا ادمن ومانجر ويوزر عادي وكل واحد ليه صلاحيات مختلفة عن التاني... القسم ده مهم جدا وهتستفاد منه جدا -Reviews, Wishlist And User Addresses +11- Reviews, Wishlist And User Addresses خلال القسم ده هنبدأ نشتغل علي التقييمات وهنشوف ازاي هنمكن المتسخدم انه يضيف تقييم علي المنتجات وكمان هنحسب متوسط عدد التقييمات علي المنتج الواحد بالاضافة للعدد الكلي للتقيمات علي المنتج الواحد ، كمان هنشرح ازاي نمكن المسخدم انه يضيف منتج لقائمة المفضلة وفي نفس الوقت يقدر يحذفه ، كمان هنمكن المستخدم من انه يضيف عنوان لدفتر العناوين بتاعه يقدر يستخدمه لما يجي يطلب اوردر . -Coupons And Shopping Cart +12- Coupons And Shopping Cart خلال القسم ده هنبدأ نمكن الادمن من انه ينشأ الكوبونات وكل كوبون بيكون ليه تاريخ معين ينتهي فيه ونسبة خصم معينة بيحددها الادمن ... والمستخدم هيقدر يستخدم الكوبون ده عشان يتسفاد من الخصم .. كمان هنمكن المستخدم من انه ينشأ سلة المنتجات اللي هيبدأ يضيف فيها المنتجات اللي عايز يشتريها ويعدل يختار ويعدل في كمية المنتجات لو متاح كمية منها في المخزن بالاضافة انه يقدر يضيف كوبون خصم علي السلة . -Cash And Online Orders, Online Payments And Deployments +13- Cash And Online Orders, Online Payments And Deployments خلال القسم ده هنبدأ نشتغل علي الاورد ر او الطلبية سواء الاوردر ده هيتم دفعه كاش او عند الاستلام او الاوردر ده هيتم دفعه من خلال بطاقة دفع او محفظة الكترنية زي ابل باي او غيره .. هيتم الربط مع بوابة الدفع ونشوف ايه وسائل الدفع اللي بتوفرها بوابة الدفع وهنعمل عميلة الدفع من خلالها ... وهنشوف ازاي بنشوف عملية الدفع نجحت ولا لا .. وازاي نعمل اوردر في حالة نجاح عملية الدفع .. هنتكلم بالتفصيل عن الدفع الكاش والدفع الالكتروني .. وفي الاخر هنرفع التطبيق علي هيروكو عشان تقدر تشاركه مع الفرونت اند او تحط اللينك في البرورتفوليو بتاعك -Security +14- Security خلال القسم ده هنتكلم شويه عن وسائل الامان اللي ممكن تستخدمها عشان تأمن التطبيق بتاعك -Enhancements +15- Enhancements خلال القسم ده هنضيف فيه التحسينات اللي هتتضاف في الكورس ... بالاضافة لو فيه مشاكل ظهرت هنسجلها فيديو ونضيفه في السكشن ده -Appendix +16- Appendix خلال القسم ده هضفلكم شويه دروس عن الجافا سكريبت عشان ترجعو ليها لو عايز تتاسس فيها عشان تساعدك وانت شغال في الكورس From 6956e29f1f1ae85cb9d5d4c39f4ad5077f3f3235 Mon Sep 17 00:00:00 2001 From: Ahmed Boghdady Date: Mon, 4 Apr 2022 00:57:54 +0200 Subject: [PATCH 8/9] Update README.md --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 21ce3b8..aaba21f 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,8 @@ This repo contains every course section in a single branch and the finished pro Choose the section branch that you study, and **final code to compare it with your own code whenever something doesn't work**! +## Join To Discord Channel For Updates [discord](https://discord.gg/e2nwBNU2q9) + 👇 **_Please read the following Frequently Asked Questions (FAQ) carefully before starting the course_** 👇 From c3a7e13e49fcee7d6f633dd6bf007206eee04910 Mon Sep 17 00:00:00 2001 From: boghdady Date: Fri, 8 Apr 2022 02:14:38 +0200 Subject: [PATCH 9/9] Section 14- Security Best Practice And Recomentations --- package-lock.json | 43 +++++++++++++++++++++++++++++++++++++++++++ package.json | 2 ++ server.js | 28 +++++++++++++++++++++++++++- utils/apiFeatures.js | 2 +- 4 files changed, 73 insertions(+), 2 deletions(-) diff --git a/package-lock.json b/package-lock.json index 4dfd3c0..e4b6ad1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -16,7 +16,9 @@ "dotenv": "^10.0.0", "express": "^4.17.1", "express-async-handler": "^1.2.0", + "express-rate-limit": "^6.3.0", "express-validator": "^6.14.0", + "hpp": "^0.2.3", "jsonwebtoken": "^8.5.1", "mongoose": "^6.0.13", "morgan": "^1.10.0", @@ -38,6 +40,9 @@ "eslint-plugin-react": "^7.28.0", "nodemon": "^2.0.15", "prettier": "^2.5.1" + }, + "engines": { + "node": "^16.13.0" } }, "node_modules/@babel/runtime": { @@ -1942,6 +1947,17 @@ "resolved": "https://registry.npmjs.org/express-async-handler/-/express-async-handler-1.2.0.tgz", "integrity": "sha512-rCSVtPXRmQSW8rmik/AIb2P0op6l7r1fMW538yyvTMltCO4xQEWMmobfrIxN2V1/mVrgxB8Az3reYF6yUZw37w==" }, + "node_modules/express-rate-limit": { + "version": "6.3.0", + "resolved": "https://registry.npmjs.org/express-rate-limit/-/express-rate-limit-6.3.0.tgz", + "integrity": "sha512-932Io1VGKjM3ppi7xW9sb1J5nVkEJSUiOtHw2oE+JyHks1e+AXuOBSXbJKM0mcXwEnW1TibJibQ455Ow1YFjfg==", + "engines": { + "node": ">= 12.9.0" + }, + "peerDependencies": { + "express": "^4" + } + }, "node_modules/express-validator": { "version": "6.14.0", "resolved": "https://registry.npmjs.org/express-validator/-/express-validator-6.14.0.tgz", @@ -2395,6 +2411,18 @@ "node": ">=8" } }, + "node_modules/hpp": { + "version": "0.2.3", + "resolved": "https://registry.npmjs.org/hpp/-/hpp-0.2.3.tgz", + "integrity": "sha512-4zDZypjQcxK/8pfFNR7jaON7zEUpXZxz4viyFmqjb3kWNWAHsLEUmWXcdn25c5l76ISvnD6hbOGO97cXUI3Ryw==", + "dependencies": { + "lodash": "^4.17.12", + "type-is": "^1.6.12" + }, + "engines": { + "node": ">=0.10.0" + } + }, "node_modules/http-cache-semantics": { "version": "4.1.0", "resolved": "https://registry.npmjs.org/http-cache-semantics/-/http-cache-semantics-4.1.0.tgz", @@ -6526,6 +6554,12 @@ "resolved": "https://registry.npmjs.org/express-async-handler/-/express-async-handler-1.2.0.tgz", "integrity": "sha512-rCSVtPXRmQSW8rmik/AIb2P0op6l7r1fMW538yyvTMltCO4xQEWMmobfrIxN2V1/mVrgxB8Az3reYF6yUZw37w==" }, + "express-rate-limit": { + "version": "6.3.0", + "resolved": "https://registry.npmjs.org/express-rate-limit/-/express-rate-limit-6.3.0.tgz", + "integrity": "sha512-932Io1VGKjM3ppi7xW9sb1J5nVkEJSUiOtHw2oE+JyHks1e+AXuOBSXbJKM0mcXwEnW1TibJibQ455Ow1YFjfg==", + "requires": {} + }, "express-validator": { "version": "6.14.0", "resolved": "https://registry.npmjs.org/express-validator/-/express-validator-6.14.0.tgz", @@ -6867,6 +6901,15 @@ "integrity": "sha512-UqBRqi4ju7T+TqGNdqAO0PaSVGsDGJUBQvk9eUWNGRY1CFGDzYhLWoM7JQEemnlvVcv/YEmc2wNW8BC24EnUsw==", "dev": true }, + "hpp": { + "version": "0.2.3", + "resolved": "https://registry.npmjs.org/hpp/-/hpp-0.2.3.tgz", + "integrity": "sha512-4zDZypjQcxK/8pfFNR7jaON7zEUpXZxz4viyFmqjb3kWNWAHsLEUmWXcdn25c5l76ISvnD6hbOGO97cXUI3Ryw==", + "requires": { + "lodash": "^4.17.12", + "type-is": "^1.6.12" + } + }, "http-cache-semantics": { "version": "4.1.0", "resolved": "https://registry.npmjs.org/http-cache-semantics/-/http-cache-semantics-4.1.0.tgz", diff --git a/package.json b/package.json index 70a3e22..8ff5848 100644 --- a/package.json +++ b/package.json @@ -18,7 +18,9 @@ "dotenv": "^10.0.0", "express": "^4.17.1", "express-async-handler": "^1.2.0", + "express-rate-limit": "^6.3.0", "express-validator": "^6.14.0", + "hpp": "^0.2.3", "jsonwebtoken": "^8.5.1", "mongoose": "^6.0.13", "morgan": "^1.10.0", diff --git a/server.js b/server.js index 446777f..5647f56 100644 --- a/server.js +++ b/server.js @@ -5,6 +5,8 @@ const dotenv = require('dotenv'); const morgan = require('morgan'); const cors = require('cors'); const compression = require('compression'); +const rateLimit = require('express-rate-limit'); +const hpp = require('hpp'); dotenv.config({ path: 'config.env' }); const ApiError = require('./utils/apiError'); @@ -35,7 +37,7 @@ app.post( ); // Middlewares -app.use(express.json()); +app.use(express.json({ limit: '20kb' })); app.use(express.static(path.join(__dirname, 'uploads'))); if (process.env.NODE_ENV === 'development') { @@ -43,6 +45,30 @@ if (process.env.NODE_ENV === 'development') { console.log(`mode: ${process.env.NODE_ENV}`); } +// Limit each IP to 100 requests per `window` (here, per 15 minutes) +const limiter = rateLimit({ + windowMs: 15 * 60 * 1000, // 15 minutes + max: 100, + message: + 'Too many accounts created from this IP, please try again after an hour', +}); + +// Apply the rate limiting middleware to all requests +app.use('/api', limiter); + +// Middleware to protect against HTTP Parameter Pollution attacks +app.use( + hpp({ + whitelist: [ + 'price', + 'sold', + 'quantity', + 'ratingsAverage', + 'ratingsQuantity', + ], + }) +); + // Mount Routes mountRoutes(app); diff --git a/utils/apiFeatures.js b/utils/apiFeatures.js index af51e2e..e2edc59 100644 --- a/utils/apiFeatures.js +++ b/utils/apiFeatures.js @@ -45,7 +45,7 @@ class ApiFeatures { { title: { $regex: this.queryString.keyword, $options: 'i' } }, { description: { $regex: this.queryString.keyword, $options: 'i' } }, ]; - } else { + } else { query = { name: { $regex: this.queryString.keyword, $options: 'i' } }; }

AltStyle によって変換されたページ (->オリジナル) /