Skip to content

Commit

Permalink
task-9
Browse files Browse the repository at this point in the history
  • Loading branch information
ivanp-epam committed Jun 26, 2021
1 parent 79febc3 commit b4fda9c
Show file tree
Hide file tree
Showing 18 changed files with 8,261 additions and 0 deletions.
3 changes: 3 additions & 0 deletions bff-service/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
CART_URL=https://CART_URL/
PRODUCT_URL=https://PRODUCT_URL/
CACHE_TTL=120
24 changes: 24 additions & 0 deletions bff-service/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
module.exports = {
parser: '@typescript-eslint/parser',
parserOptions: {
project: 'tsconfig.json',
sourceType: 'module',
},
plugins: ['@typescript-eslint/eslint-plugin'],
extends: [
'plugin:@typescript-eslint/recommended',
'plugin:prettier/recommended',
],
root: true,
env: {
node: true,
jest: true,
},
ignorePatterns: ['.eslintrc.js'],
rules: {
'@typescript-eslint/interface-name-prefix': 'off',
'@typescript-eslint/explicit-function-return-type': 'off',
'@typescript-eslint/explicit-module-boundary-types': 'off',
'@typescript-eslint/no-explicit-any': 'off',
},
};
34 changes: 34 additions & 0 deletions bff-service/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# compiled output
/dist
/node_modules

# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*

# OS
.DS_Store

# Tests
/coverage
/.nyc_output

# IDEs and editors
/.idea
.project
.classpath
.c9/
*.launch
.settings/
*.sublime-workspace

# IDE - VSCode
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
4 changes: 4 additions & 0 deletions bff-service/.prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"singleQuote": true,
"trailingComma": "all"
}
65 changes: 65 additions & 0 deletions bff-service/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# Task 9 (Backend For Frontend)

**After Lecture 8 "Docker. AWS Elastic Beanstalk"**

## Prerequisites
---

- The task is a continuation of **Homework 8**
- The task should be done in the backend repo - the same repo with **product-service** and **import-service** services
- **product-service** and **CART** services should exist and work in your application

## TASK 9.1
---

Create a folder for the **bff-service** in the same level as for other services in the repo. Create an **express** application in this folder, that listens for all requests and redirects those requests to the appropriate services based on variables provided by the **.env** file.

**bff-service** workflow example:
* Call **bff-service** by the URL: **{bff-service-url}**/**{recipient-service-name}**?var1=someValue
* **{bff-service-url}** - for example, http://localhost:3000
* **{recipient-service-name}** - ‘cart’ or ‘product’ (you can use any other mapping of your choice)
* ?var1=someValue - query string
* Get **recipientURL** from the env variables using **{recipient-service-name}** as a key
* Get request **method** (GET, POST, etc.)
* Make a new request to the needed service using the appropriate **method** and **recipientURL**
* **bff-service** should return the result of the recipient’s request

If **bff-service** cannot find **recipientURL** by the **{recipient-service-name}**, return a 'Cannot process request’ error message with status 502.
**bff-service** should return the same status code and error message that the recipient service returns to the **bff-service** in case of any error on the recipient service side.

## TASK 9.2
---

Deploy **bff-service** with Elastic Beanstalk.
* Platform should be **node.js**
* Application name must follow the following convention **{yours_github_account_login}-bff-api**
* Use the **--cname** option **{yours_github_account_login}-bff-api-{environment_name}**
* Use the **--single** option

**bff-service** should work only with requests from the **product-service** and **CART** services.
All **product-service** and **CART** services methods should work correctly if requested via **bff-service**

## Evaluation criteria (each mark includes previous mark criteria)
---

Provide your reviewers with the following information:
- link to the repo
- **product-service** service API endpoint URL
- example of the **create product** API call with all needed information: URL, payload, headers, etc.
- **CART** service API endpoint URL
- **bff-service** service URL
- example how to call **product-service** and **CART** services via **bff-service** service URL
---
* **3** - A working and correct **express** application should be in the **bff-service** folder. Reviewer can start this application locally with any valid configuration in the **.env** file and this application should works as described in the task 9.1
* **5** - The **bff-service** should be deployed with Elastic Beanstalk. The **bff-service** call should be redirected to the appropriate service : **product-service** or **CART**. The response from the **bff-service** should be the same as if **product-service** or **CART** services were called directly.

## Additional (optional) tasks
---
* **+1** - Add a cache at the **bff-service** level for a request to the **getProductsList** function of the **product-service**. The cache should expire in 2 minutes.
How to test:
* Get products list
* Create new product
* Get products list - result shouldn’t have new product
* Wait more than 2 minutes
* Get products list - result should have new product
* **+1** - Use **NestJS** to create **bff-service** instead of **express**
4 changes: 4 additions & 0 deletions bff-service/nest-cli.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"collection": "@nestjs/schematics",
"sourceRoot": "src"
}
Loading

0 comments on commit b4fda9c

Please sign in to comment.