Skip to content

Commit da18ee5

Browse files
author
Aliaksei Ladyha
committed
initial commit
0 parents  commit da18ee5

File tree

19 files changed

+953
-0
lines changed

19 files changed

+953
-0
lines changed

.gitignore

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Dependencies
2+
node_modules/
3+
4+
# Compiled output
5+
build
6+
/assets
7+
8+
# Terraform plugins and temp files
9+
.terraform
10+
terraform.tfstate
11+
terraform.tfstate.*
12+
13+
# Test coverage
14+
coverage
15+
16+
# Logs
17+
npm-debug.log*
18+
yarn-debug.log*
19+
yarn-error.log*
20+
21+
# Editors and IDEs
22+
.idea
23+
.vscode/*
24+
!.vscode/settings.json
25+
!.vscode/tasks.json
26+
!.vscode/launch.json
27+
!.vscode/extensions.json

.prettierrc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"singleQuote": true,
3+
"trailingComma": "all",
4+
"printWidth": 100,
5+
"tabWidth": 4
6+
}
7+

README.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# FE Dev proxy
2+
3+
This is an HTTP proxy which will help with FE development of ATG pages.
4+
The main and only feature is to proxy HTTP pages and replace some assets accoring to config rules.
5+
6+
### Config
7+
8+
Config file ( config.js ) is pretty staightforward. It's a node module which exports a config object
9+
10+
#### Config prams
11+
12+
`port` - (optional. default: 8888) - Local proxy server port
13+
`target` - (required) - Target webpage url, for example http://latgipo20int.schneider-electric.com
14+
`rules` - (optional, kind of...) - Array or file-replacement rules object
15+
`ruleObject.original` - (required) = RegExp or string which will be converted to regexp
16+
`ruleObject.local` - (required) = Replacement file path. Can include match groups from regex ( i.e. \$1 )
17+
18+
see included config.js as an example.
19+
20+
### Getting Started
21+
22+
Clone the repo, adjust config and develop:
23+
24+
```bash
25+
$ npm install
26+
$ npm run start
27+
```
28+
29+
Now http://localhost:8888/shop/us/en/tools/replacement-battery-selector
30+
will proxy the http://latgipo20int.schneider-electric.com/shop/us/en/tools/replacement-battery-selector
31+
with the file replacement rules applied.

bin/devproxy.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#!/usr/bin/env node
2+
3+
const path = require('path');
4+
const argv = require('minimist')(process.argv.slice(2));
5+
const fs = require('fs');
6+
7+
const { DEFAULT_CONFIG_FILENAME } = require('../lib/const');
8+
9+
function showUsage() {
10+
console.log(`
11+
devproxy init - create basic config file in the projects directory
12+
`);
13+
}
14+
15+
/**
16+
* Copies config example in to the working directory of a project
17+
*/
18+
function init() {
19+
const example = path.resolve(__dirname, '../config-examples/main.config.js');
20+
const newConfigFilename = path.join(process.cwd(), DEFAULT_CONFIG_FILENAME);
21+
fs.copyFileSync(example, newConfigFilename, fs.constants.COPYFILE_EXCL);
22+
}
23+
24+
const commands = {
25+
init: init,
26+
};
27+
28+
function main() {
29+
// running command
30+
if (commands[argv._]) {
31+
commands[argv._]();
32+
} else {
33+
require('../lib/index');
34+
}
35+
}
36+
37+
main();

config-examples/main.config.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
const fs = require('fs');
2+
const url = require('url');
3+
const path = require('path');
4+
5+
const targetUrl = url.parse(TARGET);
6+
7+
module.exports = {
8+
port: 80,
9+
sslPort: 443,
10+
localOverrides: false,
11+
target: 'https://int3.apc.com',
12+
ssl: {
13+
key: fs.readFileSync(path.resolve(__dirname, 'ssl/server.key'), 'utf8'),
14+
cert: fs.readFileSync(path.resolve(__dirname, 'ssl/server.crt'), 'utf8'),
15+
},
16+
rules: [
17+
// replacing html page with contents of other file
18+
{
19+
original: '/t/air-vapormax-2019-premium-mens-shoe-wr4C0z/AT6810-001',
20+
local: './html/air-vapormax-2019_modified.html',
21+
},
22+
// transforming html page with transform function
23+
{
24+
original: '/t/air-vapormax-2019-premium-mens-shoe-wr4C0z/AT6810-001',
25+
transform: function(body) {
26+
let b = body.replace(new RegExp(targetUrl.hostname, 'ig'), 'local.mysite.com');
27+
28+
b = b.replace(/<script.*?\/search\.js"><\/script>/gi, '');
29+
30+
return b;
31+
},
32+
},
33+
34+
// replace resource with local one
35+
{
36+
o: '/static/js/app.js',
37+
l: './build/js/app.js',
38+
},
39+
],
40+
};

lib/const.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module.exports = {
2+
DEFAULT_CONFIG_FILENAME: 'devproxy.config.js',
3+
};

lib/defaultConfig.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
const fs = require('fs');
2+
const path = require('path');
3+
4+
module.exports = {
5+
port: 8888,
6+
sslPort: 4444,
7+
localOverrides: true,
8+
// target: '',
9+
secure: false,
10+
ssl: {
11+
key: fs.readFileSync(path.resolve(__dirname, '../ssl/server.key'), 'utf8'),
12+
cert: fs.readFileSync(path.resolve(__dirname, '../ssl/server.crt'), 'utf8'),
13+
},
14+
rules: [],
15+
};

0 commit comments

Comments
 (0)