From 3cc96f0daf8557b428b4e888e7fc8a644fc3cab8 Mon Sep 17 00:00:00 2001 From: Rinat Arsaev <11846445+A77AY@users.noreply.github.com> Date: Mon, 12 Dec 2022 17:31:27 +0600 Subject: [PATCH] OPS-235: Proxy + PHP currency (#94) --- .gitignore | 3 +- .idea/vcs.xml | 12 ------- _.env | 1 + package-lock.json | 30 +++++++++++++---- package.json | 5 +-- proxy.conf.js | 32 +++++++++++++++++++ .../currency-autocomplete-field.component.ts | 16 +++++++++- 7 files changed, 76 insertions(+), 23 deletions(-) create mode 100644 _.env create mode 100644 proxy.conf.js diff --git a/.gitignore b/.gitignore index db10380ab..cb53eaa92 100644 --- a/.gitignore +++ b/.gitignore @@ -48,5 +48,6 @@ Thumbs.db # Angular .angular -# Configs +# Env and configs +.env* src/*Config*.json \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml index c42ef100e..94a25f7f4 100644 --- a/.idea/vcs.xml +++ b/.idea/vcs.xml @@ -2,17 +2,5 @@ - - - - - - - - - - - - \ No newline at end of file diff --git a/_.env b/_.env new file mode 100644 index 000000000..8b94457f6 --- /dev/null +++ b/_.env @@ -0,0 +1 @@ +PROXY_TARGET="https://sample.vality.dev" diff --git a/package-lock.json b/package-lock.json index 14074d581..bbe300c83 100644 --- a/package-lock.json +++ b/package-lock.json @@ -86,6 +86,7 @@ "@typescript-eslint/eslint-plugin": "5.31.0", "@typescript-eslint/parser": "5.31.0", "concurrently": "7.0.0", + "dotenv": "^16.0.3", "eslint": "8.20.0", "eslint-config-prettier": "8.5.0", "eslint-plugin-import": "2.26.0", @@ -7755,12 +7756,12 @@ } }, "node_modules/dotenv": { - "version": "10.0.0", - "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-10.0.0.tgz", - "integrity": "sha512-rlBi9d8jpv9Sf1klPjNfFAuWDjKLwTIJJ/VxtoTwIR6hnZxcEOQCZg2oIL3MWBYw5GpUDKOEnND7LXTbIpQ03Q==", + "version": "16.0.3", + "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.0.3.tgz", + "integrity": "sha512-7GO6HghkA5fYG9TYnNxi14/7K9f5occMlp3zXAuSxn7CKCxt9xbNWG7yF8hTCSUchlfWSe3uLmlPfigevRItzQ==", "dev": true, "engines": { - "node": ">=10" + "node": ">=12" } }, "node_modules/ecc-jsbn": { @@ -13035,6 +13036,15 @@ "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==", "dev": true }, + "node_modules/nx/node_modules/dotenv": { + "version": "10.0.0", + "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-10.0.0.tgz", + "integrity": "sha512-rlBi9d8jpv9Sf1klPjNfFAuWDjKLwTIJJ/VxtoTwIR6hnZxcEOQCZg2oIL3MWBYw5GpUDKOEnND7LXTbIpQ03Q==", + "dev": true, + "engines": { + "node": ">=10" + } + }, "node_modules/nx/node_modules/glob": { "version": "7.1.4", "resolved": "https://registry.npmjs.org/glob/-/glob-7.1.4.tgz", @@ -23266,9 +23276,9 @@ } }, "dotenv": { - "version": "10.0.0", - "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-10.0.0.tgz", - "integrity": "sha512-rlBi9d8jpv9Sf1klPjNfFAuWDjKLwTIJJ/VxtoTwIR6hnZxcEOQCZg2oIL3MWBYw5GpUDKOEnND7LXTbIpQ03Q==", + "version": "16.0.3", + "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.0.3.tgz", + "integrity": "sha512-7GO6HghkA5fYG9TYnNxi14/7K9f5occMlp3zXAuSxn7CKCxt9xbNWG7yF8hTCSUchlfWSe3uLmlPfigevRItzQ==", "dev": true }, "ecc-jsbn": { @@ -26901,6 +26911,12 @@ "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==", "dev": true }, + "dotenv": { + "version": "10.0.0", + "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-10.0.0.tgz", + "integrity": "sha512-rlBi9d8jpv9Sf1klPjNfFAuWDjKLwTIJJ/VxtoTwIR6hnZxcEOQCZg2oIL3MWBYw5GpUDKOEnND7LXTbIpQ03Q==", + "dev": true + }, "glob": { "version": "7.1.4", "resolved": "https://registry.npmjs.org/glob/-/glob-7.1.4.tgz", diff --git a/package.json b/package.json index ac0277861..0b6854f54 100644 --- a/package.json +++ b/package.json @@ -4,8 +4,8 @@ "private": true, "scripts": { "postinstall": "ngcc", - "start": "ng serve --port 8000", - "stage": "ng serve --port 8001 --configuration=stage", + "start": "ng serve --proxy-config proxy.conf.js --port 8000", + "stage": "ng serve --proxy-config proxy.conf.js --port 8001 --configuration=stage", "fix": "npm run lint-fix && npm run prettier-fix", "build": "ng build --extra-webpack-config webpack.extra.js && npm run transloco:optimize", "test": "ng test", @@ -104,6 +104,7 @@ "@typescript-eslint/eslint-plugin": "5.31.0", "@typescript-eslint/parser": "5.31.0", "concurrently": "7.0.0", + "dotenv": "^16.0.3", "eslint": "8.20.0", "eslint-config-prettier": "8.5.0", "eslint-plugin-import": "2.26.0", diff --git a/proxy.conf.js b/proxy.conf.js new file mode 100644 index 000000000..420f27ac0 --- /dev/null +++ b/proxy.conf.js @@ -0,0 +1,32 @@ +const url = require('url'); + +require('dotenv').config({ path: ['.env', process.env.NODE_ENV].filter(Boolean).join('.') }); + +const { PROXY_TARGET } = process.env; +const REQUIRED_ENV = [PROXY_TARGET]; + +if (REQUIRED_ENV.findIndex((e) => !e) !== -1) { + throw new Error('[proxy.conf.js] Set required environment variables!'); +} + +/** + * http://localhost/__subdomain to https://subdomain.target.com + */ +function createSubdomainByPathProxy(target, subdomainPathPrefix = '__') { + const SUBDOMAIN_PARAM_REGEXP = `^/${subdomainPathPrefix}(?[a-zA-Z0-9-]+)`; + const { host, port, protocol } = url.parse(target); + return { + context: `/${subdomainPathPrefix}*/**`, + target: 'localhost', + router: function (req) { + const param = req.url.match(new RegExp(SUBDOMAIN_PARAM_REGEXP)).groups.param; + return `${protocol}//${param}.${host}${port ? `:${port}` : ''}`; + }, + pathRewrite: { [SUBDOMAIN_PARAM_REGEXP]: '' }, + secure: false, + logLevel: 'debug', + changeOrigin: true, + }; +} + +module.exports = [createSubdomainByPathProxy(PROXY_TARGET)]; diff --git a/src/app/shared/components/inputs/currency-autocomplete-field/currency-autocomplete-field.component.ts b/src/app/shared/components/inputs/currency-autocomplete-field/currency-autocomplete-field.component.ts index 8cf0d0580..6b1b55bd5 100644 --- a/src/app/shared/components/inputs/currency-autocomplete-field/currency-autocomplete-field.component.ts +++ b/src/app/shared/components/inputs/currency-autocomplete-field/currency-autocomplete-field.component.ts @@ -14,7 +14,21 @@ export class CurrencyAutocompleteFieldComponent extends WrappedFormControlSuperc @Input() label: string; @Input() @coerceBoolean required = false; - options: Option[] = ['RUB', 'USD', 'EUR', 'UAH', 'KZT', 'BYN', 'JPY', 'INR', 'AZN', 'BRL', 'BDT', 'TRY'] + options: Option[] = [ + 'RUB', + 'USD', + 'EUR', + 'UAH', + 'KZT', + 'BYN', + 'JPY', + 'INR', + 'AZN', + 'BRL', + 'BDT', + 'TRY', + 'PHP', + ] .sort() .map((currency) => ({ label: currency, value: currency }));