Skip to content

Commit

Permalink
OPS-235: Proxy + PHP currency (#94)
Browse files Browse the repository at this point in the history
  • Loading branch information
A77AY authored Dec 12, 2022
1 parent b8ae56c commit 3cc96f0
Show file tree
Hide file tree
Showing 7 changed files with 76 additions and 23 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,6 @@ Thumbs.db
# Angular
.angular

# Configs
# Env and configs
.env*
src/*Config*.json
12 changes: 0 additions & 12 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions _.env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
PROXY_TARGET="https://sample.vality.dev"
30 changes: 23 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
32 changes: 32 additions & 0 deletions proxy.conf.js
Original file line number Diff line number Diff line change
@@ -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}(?<param>[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)];
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,21 @@ export class CurrencyAutocompleteFieldComponent extends WrappedFormControlSuperc
@Input() label: string;
@Input() @coerceBoolean required = false;

options: Option<string>[] = ['RUB', 'USD', 'EUR', 'UAH', 'KZT', 'BYN', 'JPY', 'INR', 'AZN', 'BRL', 'BDT', 'TRY']
options: Option<string>[] = [
'RUB',
'USD',
'EUR',
'UAH',
'KZT',
'BYN',
'JPY',
'INR',
'AZN',
'BRL',
'BDT',
'TRY',
'PHP',
]
.sort()
.map((currency) => ({ label: currency, value: currency }));

Expand Down

0 comments on commit 3cc96f0

Please sign in to comment.