Skip to content

virtual/microservices-ticketing

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Ticketing App

Ticketing app following along with Microservices with Node and React

Development

  • Run skaffold dev to start the development K8s/Docker files

Routes*

  • We will use express-validator to validate input (req.body) as route middleware

    • validation: making sure the input is what we intend
    • sanitization: changing the input to what we need
    • Use validationResult to pull out the error messages produced during validation step
router.post(
  '/api/users/signup',
  [
    body('email').isEmail().withMessage('Email must be valid'),
    body('password').isString()
  ],
  (req, res) => {
    ...

Auth Routes

Route Method Body Purpose
/api/users/signup POST {email: string, password: string} Sign up for an account
/api/users/signin POST {email: string, password: string} Sign in to an existing account
/api/users/signout POST {} Sign out
/api/user/currentuser GET Return info about the user

* Tables generated with https://www.tablesgenerator.com/markdown_tables#

Notes

Error responses

  • As we include more microservices (possibly built using different frameworks/langauges), the error objects may also be formatted differently
  • We need to define the format of the error object returned to be consistent for the React front-end
  • Express error handling lets you create a custom middleware function for error handling; it must include 4 arguments in order to know that it is an error handling middleware
  • Using express-async-errors for throwing async errors
app.use(function (err, req, res, next) {
  console.error(err.stack);
  res.status(500).send('Something broke!');
});

Common error response for this project:

{
  errors: {
    message: string,
    field?: string
  }[]
}

Abstract Class

  • To ensure the error object/serializeError() method is consistent, we will use an abstract class (instead of Interface)
  • Cannot be initiated
  • Used to setup requirements for subclasses
  • Does create a class when translated to JS, which means we can check it as instanceOf (interfaces don't exist in JS)

SSL Error on dev

  • Ingress is setup to use https by default
  • To get around browser warning: type thisisunsafe in the Chrome privacy window