Skip to content

Latest commit

 

History

History
132 lines (97 loc) · 3.22 KB

section-12.md

File metadata and controls

132 lines (97 loc) · 3.22 KB

Section 12: Code Sharing and Reuse Between Services

Table of Contents

Shared Logic Between Services

  • What about event-related stuff for the auth service?
  • It turns out that no other services really need to know about what the auth service is doing!
  • Everything the auth service does is exposed through that JWT in the cookie

⬆ back to top

Options for Code Sharing

Option #3 is selected

⬆ back to top

NPM Organizations

⬆ back to top

Publishing NPM Modules

npm init -y
git init
git add .
git commit -m "initial commit"
npm login
npm publish --access public

⬆ back to top

Project Setup

  • There might be differences in our TS settings between the common lib and our services - don't want to deal with that
  • Services might not be written with TS at all!
  • Our common library will be written as Typescript and published as Javascript
cd section-12/ticketing/common
tsc --init

⬆ back to top

An Easy Publish Command

git status
git add .
git commit -m "additional config"
npm version patch
npm run build
npm login
npm publish --access public

⬆ back to top

Relocating Shared Code

  • move errors and middlewares from auth services to common npm module
  • install necessary libraries
npm i express express-validator cookie-session jsonwebtoken @types/cookie-session @types/express @types/jsonwebtoken
npm run pub

⬆ back to top

Updating Import Statements

npm i @chticketing/common
import { errorHandler, NotFoundError } from '@chticketing/common';

⬆ back to top

Updating the Common Module

cd section-12/ticketing/common
npm run pub
cd ../auth
npm update @chticketing/common
kubectl get pods
kubectl exec -it auth-depl-86c85d4895-n4bp4 sh
/app # cd node_modules/@chticketing/common
/app # cat package.json

⬆ back to top