Today you will practice Layered Structure, Middlewares and Schema Validation
-
Go to
'./controllers/jediController.js'
and replace client response errors to proper Error with status (TODO 1-4) -
Go to
'./middleware/validation/jediSchema.js'
and all missing fields to schema validation. (TODO 5)- height - should be between 0 and 300
- mass - should be greater than 0
- hair_color - string more than 3 chars
- skin_color - string more than 3 chars
- birth_year - string more than 4 chars
- eye_color - string more than 4 chars
- gender - string For validation schema option check docs: https://express-validator.github.io/docs/schema-validation.html
-
Add Jedi Schema Validation (TODO 6) for missing route (think which one)
-
Add auth middleware in
./middleware/auth.js
(TODO 7)- The main idea is to check that request has header "Authorization" and it contains secret republic key "may_the_force_be_with_you"
- Use in Postman "Bearer" authorization and get rid of "Bearer" substring in your middleware in the beginning of the value of authorization key
- Don't forget to export auth middleware function
- Go to
jediRoutes.jb
and import auth middleware (TODO 8) - Add auth middleware to all our routes. We want only those that with a key access our jedis
-
Test that everything is working!