Skip to content

Commit

Permalink
Merge pull request #2 from fga-eps-mds/173_organizar_gateway
Browse files Browse the repository at this point in the history
♻️ 173 organizar gateway
  • Loading branch information
DaviMatheus authored Nov 23, 2023
2 parents ce1e3c9 + 5157b2c commit 546a68f
Show file tree
Hide file tree
Showing 12 changed files with 87 additions and 13 deletions.
9 changes: 8 additions & 1 deletion .eslintrc.js → .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ module.exports = {
"es2021": true,
"node": true
},
"extends": "eslint:recommended",
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/recommended"
],
"overrides": [
{
"env": {
Expand All @@ -17,10 +20,14 @@ module.exports = {
}
}
],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": "latest",
"sourceType": "module"
},
"plugins": [
"@typescript-eslint"
],
"rules": {
}
}
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -145,4 +145,6 @@ dist
package-lock.json
yarn.lock

reports/*
reports/*

config.yml
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

## Quality Control

[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=fga-eps-mds_2023.2-PrintGo-PrinterService&metric=alert_status)](https://sonarcloud.io/summary/new_code?id=fga-eps-mds_2023.2-PrintGo-PrinterService)



## Sobre
Expand Down
6 changes: 6 additions & 0 deletions babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = {
presets: [
['@babel/preset-env', {targets: {node: 'current'}}],
'@babel/preset-typescript',
],
};
7 changes: 7 additions & 0 deletions config.dev.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
services:
- name: user
url: http://localhost:8000
- name: printer
url: http://localhost:8001
- name: schedular
url: 2023-1-schedula-gerenciador-de-localidades.vercel.app
7 changes: 7 additions & 0 deletions config.prod.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
services:
- name: user
url: http://localhost:8000
- name: printer
url: http://localhost:8001
- name: schedular
url: 2023-1-schedula-gerenciador-de-localidades.vercel.app
4 changes: 3 additions & 1 deletion config.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
services:
- name: user
url: http://localhost:8000
url: http://localhost:8000
- name: printer
url: http://localhost:8001
8 changes: 8 additions & 0 deletions nodemon.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"watch": ["./src", "."],
"ext": ".ts,.js,.yml",
"ignore": [],
"exec": "ts-node ./src/gateway.ts",
"legacyWatch": true

}
23 changes: 19 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
{
"name": "printgo-gateway",
"version": "1.0.0",
"type": "module",
"description": "",
"main": "index.js",
"scripts": {
"start": "nodemon src/gateway.js",
"start": "nodemon",
"test": "jest --passWithNoTests --no-cache --runInBand",
"test:all": "CI=true npm run test -- --coverage",
"lint": "eslint --ext .ts",
Expand All @@ -15,6 +14,10 @@
"author": "",
"license": "ISC",
"dependencies": {
"@types/cors": "^2.8.17",
"@types/express-http-proxy": "^1.6.6",
"@types/js-yaml": "^4.0.9",
"@types/morgan": "^1.9.9",
"axios": "^1.6.0",
"cors": "^2.8.5",
"cross-env": "^7.0.3",
Expand All @@ -26,10 +29,22 @@
"morgan": "^1.10.0"
},
"devDependencies": {
"eslint": "^8.52.0",
"@babel/cli": "^7.23.4",
"@babel/core": "^7.23.3",
"@babel/preset-env": "^7.23.3",
"@babel/preset-typescript": "^7.23.3",
"@types/express": "^4.17.21",
"@types/jest": "^29.5.10",
"@types/node": "^20.9.4",
"@typescript-eslint/eslint-plugin": "^6.12.0",
"@typescript-eslint/parser": "^6.12.0",
"eslint": "^8.54.0",
"jest-mock-extended": "^3.0.5",
"jest-sonar": "^0.2.16",
"jest-sonar-reporter": "^2.0.0",
"nodemon": "^3.0.1"
"nodemon": "^3.0.1",
"ts-node": "^10.9.1",
"ts-node-dev": "^2.0.0",
"typescript": "^5.3.2"
}
}
4 changes: 2 additions & 2 deletions sonar-project.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ sonar.organization=fga-eps-mds-1
sonar.sources=src
sonar.tests=tests

sonar.language=js
sonar.language=ts

sonar.test.inclusions=**/*.spec.jsx,**/*.spec.js, **/*.test.js
sonar.test.inclusions=**/*.spec.tsx,**/*.spec.ts, **/*.test.ts
sonar.exclusions=node_modules/**, test/**, assets/**, .github/**, scripts/**


Expand Down
12 changes: 8 additions & 4 deletions src/gateway.js → src/gateway.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@ import httProxy from 'express-http-proxy'
import { resolve } from 'path'
import { readFileSync } from 'fs'
import { load } from 'js-yaml'
const app = express();

const app = express();
const pathFile = resolve(process.cwd(), 'config.yml')
const readConfig = readFileSync(pathFile, {encoding: 'utf8'})
const { services } = load(readConfig, {json: true})

// eslint-disable-next-line @typescript-eslint/no-explicit-any
const {services}: any= load(readConfig, {json: true})

app.use(express.json());

Expand All @@ -23,8 +25,10 @@ app.get('/', (req, res) => {
return res.json({ message: 'Running Gateway' })
})

services.forEach(({ name, url }) => {
app.use(`/${name}`, httProxy(url, {timeout: 3000}))
services.forEach(({ url }) => {
console.log(url);

app.use("/", httProxy(url, {timeout: 5000}))

});

Expand Down
14 changes: 14 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"compilerOptions": {
/* Visit https://aka.ms/tsconfig to read more about this file */
"target": "es2016", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
"module": "NodeNext", /* Specify what module code is generated. */
"rootDir": "./src", /* Specify the root folder within your source files. */
"outDir": "./dist", /* Specify an output folder for all emitted files. */
"esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */
"forceConsistentCasingInFileNames": true, /* Ensure that casing is correct in imports. */
"strict": false, /* Enable all strict type-checking options. */
"skipLibCheck": true,

},
}

0 comments on commit 546a68f

Please sign in to comment.