diff --git a/.eslintrc.js b/.eslintrc.cjs similarity index 70% rename from .eslintrc.js rename to .eslintrc.cjs index 791d970..c706c0f 100644 --- a/.eslintrc.js +++ b/.eslintrc.cjs @@ -3,7 +3,10 @@ module.exports = { "es2021": true, "node": true }, - "extends": "eslint:recommended", + "extends": [ + "eslint:recommended", + "plugin:@typescript-eslint/recommended" + ], "overrides": [ { "env": { @@ -17,10 +20,14 @@ module.exports = { } } ], + "parser": "@typescript-eslint/parser", "parserOptions": { "ecmaVersion": "latest", "sourceType": "module" }, + "plugins": [ + "@typescript-eslint" + ], "rules": { } } diff --git a/.gitignore b/.gitignore index d734e7b..9e46eef 100644 --- a/.gitignore +++ b/.gitignore @@ -145,4 +145,6 @@ dist package-lock.json yarn.lock -reports/* \ No newline at end of file +reports/* + +config.yml \ No newline at end of file diff --git a/README.md b/README.md index a2488b4..929fbb7 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/babel.config.js b/babel.config.js new file mode 100644 index 0000000..a50f080 --- /dev/null +++ b/babel.config.js @@ -0,0 +1,6 @@ +module.exports = { + presets: [ + ['@babel/preset-env', {targets: {node: 'current'}}], + '@babel/preset-typescript', + ], + }; \ No newline at end of file diff --git a/config.dev.yml b/config.dev.yml new file mode 100644 index 0000000..0ac9894 --- /dev/null +++ b/config.dev.yml @@ -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 \ No newline at end of file diff --git a/config.prod.yml b/config.prod.yml new file mode 100644 index 0000000..0ac9894 --- /dev/null +++ b/config.prod.yml @@ -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 \ No newline at end of file diff --git a/config.yml b/config.yml index c231c8c..1a1b97a 100644 --- a/config.yml +++ b/config.yml @@ -1,3 +1,5 @@ services: - name: user - url: http://localhost:8000 \ No newline at end of file + url: http://localhost:8000 + - name: printer + url: http://localhost:8001 \ No newline at end of file diff --git a/nodemon.json b/nodemon.json new file mode 100644 index 0000000..71f74ea --- /dev/null +++ b/nodemon.json @@ -0,0 +1,8 @@ +{ + "watch": ["./src", "."], + "ext": ".ts,.js,.yml", + "ignore": [], + "exec": "ts-node ./src/gateway.ts", + "legacyWatch": true + + } \ No newline at end of file diff --git a/package.json b/package.json index 5652d8b..e42bc9e 100644 --- a/package.json +++ b/package.json @@ -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", @@ -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", @@ -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" } } diff --git a/sonar-project.properties b/sonar-project.properties index 54e1248..24671f8 100644 --- a/sonar-project.properties +++ b/sonar-project.properties @@ -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/** diff --git a/src/gateway.js b/src/gateway.ts similarity index 77% rename from src/gateway.js rename to src/gateway.ts index adc7c57..9e9ba1b 100644 --- a/src/gateway.js +++ b/src/gateway.ts @@ -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()); @@ -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})) }); diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..f928171 --- /dev/null +++ b/tsconfig.json @@ -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, + + }, +}