Giter Club home page Giter Club logo

spa-mcn's Introduction

Single-Page Application Demo

Aggregate test coverage for all components in this repo: Coverage Status

This application demos a modern single-page application built on:

  • Vue.js (front-end)
  • Node.js (back-end)
  • MongoDB (database)

This application was created to help train people on NGINX and the F5 Distributed Cloud Services capabilities. It is featured in the Modern Apps Jumpstart Workshop.

Brewz Site

Components

Frontend

Vue.JS application written in TypeScript that simulates a shopping cart application.

  • Environment: Internet facing

API

Node.JS application running on Express.JS that provides the primary API and access to the database.

  • Environment: Internet facing

Database

MongoDB database that stores information about the user and the products. This database is seeded with user and product data on launch.

  • Environment: Internal

Recommendations

Node.JS microservice that will recommend products.

  • Environment: Internet facing

Inventory

Node.JS microservice that will tell the local store inventory. Note, this microservice is accessed through the API and simulates the API server talking to an internal service.

  • Environment: Internal, accessibly by the API server

Checkout

Node.JS microservice that will complete the ordering process.

  • Environment: Internet facing

Features

Product Detail

The Product detail page contains the recommendations and inventory microservices.

Product Detail

Deploy

docker-compose up -d

Development

back-end services (api, inventory, recommendations)

Running

cd <service folder here>
export MONGO_URL="localhost"
export INVENTORY_URL="http://localhost:8002"
export RECOMMENDATIONS_URL="http://recommendations:8001"
npm dev

Optionally, to run the dark variant of the Brewz SPA app: npm run dev:dark.

To show the security features of the app (sign in, etc), you will need to navigate to /config in the Brewz app, set the Enable Security checkbox, then refresh your browser.

Alternative Product Catalog

By default, this sample application shows beer products, but it can also be configured to show coffee instead. To do this, set a runtime environment variable on the mongodb, api and recommendations containers:

PRODUCT_TYPE=coffee

Unit Tests

cd <service folder here>
npm run test:unit

Code Coverage Metrics

cd <service folder here>
npm run test:coverage

Coverage reports will appear in each subproject's coverage directory.

spa (front-end)

cd spa
npm run dev

You will also need to update the ./spa/.env with the correct API server URL.

Docker Compose

You can use the docker-compose file leveraged in production for development as well.

docker-compose up -d

To stop the container you want to do development on and run it locally:

docker-compose rm -sv container-name

Then start your front-end or back-end as shown above.

NGINX

To host the Brewz app, you will need a proxy such as NGINX to route the SPA requests to the correct upstream service. The following NGINX conf will accomplish this:

server {
  listen 8080;
  location / { proxy_pass http://127.0.0.1:8081/; }
  location /api { proxy_pass http://127.0.0.1:8000; }
  location /images { proxy_pass http://127.0.0.1:8000/images; }
  location /recommendations { proxy_pass http://127.0.0.1:8001; }
  location /inventory { proxy_pass http://127.0.0.1:8002; }
  location /checkout { proxy_pass http://127.0.0.1:8003; }
}  

Attribution

This code is based on the work of Shaun Wassell and his Creating and Hosting a Full-Stack Site LinkedIn Learning course.

I have extended this demo to:

  • run components in docker containers
  • abstract API and image URLs
  • seed MongoDB
  • recommendations microservice
  • checkout (ordering) microservice
  • store inventory simulation
  • stats page for all services
  • use OIDC and OAuth 2 for authentication/authorization to spa app and backend services via JWT

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.