GithubHelp home page GithubHelp logo

webmakaka / microservices-with-node-js-and-react-improved Goto Github PK

View Code? Open in Web Editor NEW
25.0 2.0 23.0 192 KB

[Stephen Grider] Microservices with Node JS and React [ENG, 2021]

Dockerfile 1.22% TypeScript 88.29% JavaScript 10.50%
nodejs docker kubernetes microservices typescript mongodb jest ubuntu stripe curl reactjs mongoose nextjs supertest minikube nats-streaming-server skaffold helm

microservices-with-node-js-and-react-improved's Introduction

[Stephen Grider] Microservices with Node JS and React [ENG, 2021]



Here we will develop only project 2 from course.


Preparation

I am working in ubuntu linux 20.04.

Minikube, Kubectl, Docker, Skaffold should be installed.


$ sudo apt install -y jq

Minikube setup

$ curl -Lo minikube https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64 && chmod +x minikube && sudo mv minikube /usr/local/bin/

Kubectl setup

$ curl -LO https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl && chmod +x kubectl && sudo mv kubectl /usr/local/bin/

Skaffold setup

$ curl -Lo skaffold https://storage.googleapis.com/skaffold/releases/latest/skaffold-linux-amd64 && chmod +x ./skaffold && sudo mv ./skaffold /usr/local/bin

Run minikube


$ export \
    PROFILE=microservices-with-nodejs-and-react \
    MEMORY=8192 \
    CPUS=4 \
    DRIVER=docker \
    KUBERNETES_VERSION=v1.22.4

$ {
    minikube --profile ${PROFILE} config set memory ${MEMORY}
    minikube --profile ${PROFILE} config set cpus ${CPUS}
    minikube --profile ${PROFILE} config set disk-size 20g

    minikube --profile ${PROFILE} config set vm-driver ${DRIVER}

    minikube --profile ${PROFILE} config set kubernetes-version ${KUBERNETES_VERSION}
    minikube start --profile ${PROFILE} --embed-certs

    // Enable ingress
    minikube addons --profile ${PROFILE} enable ingress

    // Enable registry
    // minikube addons --profile ${PROFILE} enable registry
}

$ minikube --profile ${PROFILE} ip
192.168.49.2

$ sudo vi /etc/hosts
#---------------------------------------------------------------------
# Minikube
#---------------------------------------------------------------------
192.168.49.2 ticketing.dev

How to run project in development mode (current version)


$ kubectl create secret generic jwt-secret --from-literal=JWT_KEY=MY_JWT_SECRET

stripe.com

Developers --> API keys


// <STRIPE_SECRET_KEY> from stripe.com
$ kubectl create secret generic stripe-secret --from-literal=STRIPE_KEY=<STRIPE_SECRET_KEY>

app/client/src/pages/orders/[orderId].js

Set your stripeKey (stripe public key) instead mine.


Need to update baseURL (Ingress HostName).

/app/client/src/api


// It will show after skaffold starts
$ kubectl get ingress
NAME          CLASS    HOSTS           ADDRESS        PORTS   AGE
ingress-svc   <none>   ticketing.dev   192.168.49.2   80      8m41s

Take ADDRESS and modify baseURL.


baseURL should looks like:


192-168-49-2.kubernetes.default.svc.cluster.local

more details


$ cd skaffold

Need to update my docker image name webmakaka/microservices*** to your in scripts from skaffold and k8s folders.

$ skaffold dev

$ kubectl get pods
NAME                                           READY   STATUS    RESTARTS   AGE
auth-deployment-84bffc5564-cjqzt               1/1     Running   0          64s
auth-mongo-deployment-57db5fc46f-9g7wh         1/1     Running   0          64s
client-deployment-77f9896bdb-zdwwg             1/1     Running   0          64s
expiration-deployment-69b678458d-l5w2p         1/1     Running   0          63s
expiration-redis-deployment-777554b4f8-vkttt   1/1     Running   0          63s
nats-deployment-6486d9669f-lmv8p               1/1     Running   0          63s
orders-deployment-765c6cfc5b-kcjpr             1/1     Running   0          63s
orders-mongo-deployment-5997f95f7f-hzf4l       1/1     Running   0          63s
payments-deployment-bff95d98c-qv6w4            1/1     Running   0          63s
payments-mongo-deployment-7ccdb6f6c9-tqlzk     1/1     Running   0          63s
tickets-deployment-79b9854cdf-5d8ld            1/1     Running   0          63s
tickets-mongo-deployment-545dc7d7c5-md59k      1/1     Running   0          63s

chrome browser -> https://ticketing.dev/


type: thisisunsafe in the browser window with security warning.


Requests to app

// SIGN UP
$ curl \
    --insecure \
    --cookie-jar /tmp/cookies.txt \
    --data '{"email":"[email protected]", "password":"123456789"}' \
    --header "Content-Type: application/json" \
    --request POST \
    --url https://ticketing.dev/api/users/signup \
    | jq

// SIGN IN
$ curl \
    --data '{"email":"[email protected]", "password":"123456789"}' \
    --header "Content-Type: application/json" \
    --request POST \
    --url http://ticketing.dev/api/users/signin \
    | jq

// GET CURRENT USER
$ curl \
    --insecure \
    --cookie /tmp/cookies.txt \
    --header "Content-Type: application/json" \
    --request GET \
    --url https://ticketing.dev/api/users/currentuser \
    | jq

// CREATE TICKET
$ curl \
    --insecure \
    --cookie /tmp/cookies.txt \
    --data '{"title":"concert", "price":10}' \
    --header "Content-Type: application/json" \
    --request POST \
    --url https://ticketing.dev/api/tickets \
    | jq

// GET ALL TICKETS
$ curl \
    --insecure \
    --header "Content-Type: application/json" \
    --request GET \
    --url https://ticketing.dev/api/tickets/ \
    | jq

// GET TICKET
$ curl \
    --insecure \
    --header "Content-Type: application/json" \
    --request GET \
    --url https://ticketing.dev/api/tickets/6037eaacbcc4a0001acb6d50 \
    | jq

// UPDATE TICKET
$ curl \
    --insecure \
    --cookie /tmp/cookies.txt \
    --data '{"title":"new concert", "price":100}' \
    --header "Content-Type: application/json" \
    --request PUT \
    --url https://ticketing.dev/api/tickets/603b0e8036b9f80019154277 \
    | jq

// CREATE ORDER
$ curl \
    --insecure \
    --cookie /tmp/cookies.txt \
    --data '{"ticketId":"604150ce9a43b7001a54b720"}' \
    --header "Content-Type: application/json" \
    --request POST \
    --url https://ticketing.dev/api/orders \
    | jq

// GET ALL ORDERS
$ curl \
    --insecure \
    --cookie /tmp/cookies.txt \
    --header "Content-Type: application/json" \
    --request GET \
    --url https://ticketing.dev/api/orders \
    | jq

// GET SINGLE ORDER
$ curl \
    --insecure \
    --cookie /tmp/cookies.txt \
    --header "Content-Type: application/json" \
    --request GET \
    --url https://ticketing.dev/api/orders/604150e7d42b880019802e99 \
    | jq

// CREATE PAYMENT
$ curl \
    --insecure \
    --cookie /tmp/cookies.txt \
    --data '{"orderId":"5ec6c93f6c627e0023725faf", "token": "tok_visa"}' \
    --header "Content-Type: application/json" \
    --request POST \
    --url https://ticketing.dev/api/payments/ \
    | jq




Marley

Any questions in english: Telegram Chat
Любые вопросы на русском: Телеграм чат

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.