Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

task-9 #7

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions bff-service/.ebextensions/01_envar.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
option_settings:
aws:elasticbeanstalk:application:environment:
PORT: 4000
NODE_ENV: production
CART_URL: "https://6ux44zy8w5.execute-api.eu-west-1.amazonaws.com/dev/api"
PRODUCT_URL: "https://vmle7gk5m6.execute-api.eu-west-1.amazonaws.com/dev"
CACHE_TTL: 120
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',
},
};
38 changes: 38 additions & 0 deletions bff-service/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# 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
# Elastic Beanstalk Files
.elasticbeanstalk/*
!.elasticbeanstalk/*.cfg.yml
!.elasticbeanstalk/*.global.yml
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"
}
1 change: 1 addition & 0 deletions bff-service/Procfile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
web: npm run start:prod
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