-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
76 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,5 +48,6 @@ Thumbs.db | |
# Angular | ||
.angular | ||
|
||
# Configs | ||
# Env and configs | ||
.env* | ||
src/*Config*.json |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
PROXY_TARGET="https://sample.vality.dev" |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters