Skip to content
This repository was archived by the owner on Apr 8, 2024. It is now read-only.

Commit 38e32e9

Browse files
Adam GrohsAdam Grohs
Adam Grohs
authored and
Adam Grohs
committed
initial import
1 parent db00a14 commit 38e32e9

17 files changed

+18419
-1
lines changed

.circleci/config.yml

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
version: 2
2+
jobs:
3+
build:
4+
docker:
5+
- image: 'circleci/node:lts'
6+
steps:
7+
- checkout
8+
- run: yarn clean-install
9+
- save_cache:
10+
paths:
11+
- node_modules
12+
key: micro-cors-http-proxy-{{ checksum "package.json" }}
13+
test:
14+
docker:
15+
- image: 'circleci/node:lts'
16+
steps:
17+
- checkout
18+
- restore_cache:
19+
keys:
20+
- micro-cors-http-proxy-{{ checksum "package.json" }}
21+
- run: yarn clean-install
22+
- run: yarn test
23+
release:
24+
docker:
25+
- image: 'circleci/node:lts'
26+
steps:
27+
- checkout
28+
- restore_cache:
29+
keys:
30+
- micro-cors-http-proxy-{{ checksum "package.json" }}
31+
- run: yarn clean-install
32+
- run: npx semantic-release
33+
workflows:
34+
version: 2
35+
build_test_release:
36+
jobs:
37+
- build
38+
- test:
39+
requires:
40+
- build
41+
- release:
42+
filters:
43+
branches:
44+
only:
45+
- master
46+
requires:
47+
- test

.github/ISSUE_TEMPLATE/bug_report.md

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
---
2+
name: Bug report
3+
about: Create a report to help us improve
4+
title: ''
5+
labels: ''
6+
assignees: ''
7+
---
8+
9+
**Describe the bug**
10+
A clear and concise description of what the bug is.
11+
12+
**To Reproduce**
13+
Steps to reproduce the behavior:
14+
15+
1. Go to '...'
16+
2. Click on '....'
17+
3. Scroll down to '....'
18+
4. See error
19+
20+
**Expected behavior**
21+
A clear and concise description of what you expected to happen.
22+
23+
**Screenshots**
24+
If applicable, add screenshots to help explain your problem.
25+
26+
**Desktop (please complete the following information):**
27+
28+
- OS: [e.g. iOS]
29+
- Browser [e.g. chrome, safari]
30+
- Version [e.g. 22]
31+
32+
**Smartphone (please complete the following information):**
33+
34+
- Device: [e.g. iPhone6]
35+
- OS: [e.g. iOS8.1]
36+
- Browser [e.g. stock browser, safari]
37+
- Version [e.g. 22]
38+
39+
**Additional context**
40+
Add any other context about the problem here.
+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
---
2+
name: Feature request
3+
about: Suggest an idea for this project
4+
title: ''
5+
labels: ''
6+
assignees: ''
7+
---
8+
9+
**Is your feature request related to a problem? Please describe.**
10+
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
11+
12+
**Describe the solution you'd like**
13+
A clear and concise description of what you want to happen.
14+
15+
**Describe alternatives you've considered**
16+
A clear and concise description of any alternative solutions or features you've considered.
17+
18+
**Additional context**
19+
Add any other context or screenshots about the feature request here.

.gitignore

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# dependencies
2+
node_modules
3+
4+
# misc
5+
.env
6+
*.log

.nowignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
*.test.*
2+
*.spec.*
3+
/__tests__/

.prettierrc

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"singleQuote": true,
3+
"semi": false,
4+
"trailingComma": "none"
5+
}

.whitesource

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
##########################################################
2+
#### WhiteSource Integration configuration file ####
3+
##########################################################
4+
5+
# Configuration #
6+
#---------------#
7+
ws.repo.scan=true
8+
vulnerable.check.run.conclusion.level=failure

LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2019-2025 UNIQUELY PARTICULAR LLC and Adam Grohs
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

+74-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,74 @@
1-
# micro-http-proxy
1+
# @particular./micro-cors-http-proxy
2+
3+
[![npm version](https://img.shields.io/npm/v/@particular./micro-cors-http-proxy.svg)](https://www.npmjs.com/package/@particular./micro-cors-http-proxy) [![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg)](https://github.com/semantic-release/semantic-release) [![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg)](https://github.com/prettier/prettier) [![CircleCI](https://img.shields.io/circleci/project/github/uniquelyparticular/micro-cors-http-proxy.svg?label=circleci)](https://circleci.com/gh/uniquelyparticular/micro-cors-http-proxy)
4+
5+
> 🎮 Minimal HTTP Proxy implementation to support secure whitelisting and CORS
6+
7+
Built with [Micro](https://github.com/zeit/micro)! 🤩
8+
9+
## 🛠 Setup
10+
11+
Create a `.env` at the project root with the following credentials:
12+
13+
```dosini
14+
PROXY_PREFIX=proxy
15+
PROXY_REFERER_WHITELIST=localhost,*.zendesk.com,*.myshopify.com,*.now.sh
16+
PROXY_DESTINATION_WHITELIST=api.stripe.com,api.goshippo.com,api.shipengine.com,api.moltin.com,*.myshopify.com,*.salesforce.com,*.demandware.net
17+
```
18+
19+
`PROXY_PREFIX` is optional and will default to `'proxy'` but is used in the URI patterns to determine where to find the encoded uri to proxy request to (ie. `https://12345678.ngrok.io/<<<PROXY_PREFIX>>>/https%3A%2F%2Fapi.somethingsecure.com%2Fadmin%2Fcustomers.json`)
20+
21+
`PROXY_REFERER_WHITELIST` is a comma separated list of patterns to match against the incoming requests 'Referer' header (ex. `localhost,*.myawesomesite.com,*.now.sh`)
22+
_(and yes, 'REFERER' is intentionally misspelled to match the http header! 😉)_
23+
24+
`PROXY_DESTINATION_WHITELIST` is a comma separated list of patterns to match against the URI you are proxying requests to. (ex. `api.somethingsecure.com,*.somotherapi.com`)
25+
26+
## 📦 Package
27+
28+
Run the following command to build the app
29+
30+
```bash
31+
yarn install
32+
```
33+
34+
Start the development server
35+
36+
```bash
37+
yarn dev
38+
```
39+
40+
The server will typically start on PORT `3000`. If not, you'll need to restart ngrok to point to whatever server port you've started here.
41+
42+
## ⛽️ Usage
43+
44+
To send requests to the proxy, the calling implementation should use `encodeURIComponent` to encode the portion of the URI after the `PROXY_PREFIX`.
45+
46+
Once your server is up and running, you can send `GET`, `DELETE`, `OPTIONS`, `PATCH`, `PUT` and `POST` requests to it, ensuring that you are URIencoding the value after your `PROXY_PREFIX`. (ex. `https://<<<NGROK_URL>>>/<<<PROXY_PREFIX>>>/https%3A%2F%2Fapi.somewheresecure.com%2Fsomemethod`)
47+
48+
Sample call using [jQuery.get()](https://api.jquery.com/jquery.get/) below:
49+
50+
```js
51+
const sampleEndpoint = `https://12345678.ngrok.io//proxy/${encodeURIComponent(
52+
'https://23456789.myshopify.com/admin/customers.json'
53+
)}`
54+
55+
$.ajax({
56+
url: sampleEndpoint,
57+
type: 'GET',
58+
corse: true,
59+
beforeSend: xhr => {
60+
xhr.setRequestHeader(
61+
'X-Shopify-Access-Token',
62+
'1XXXXXxxxxxXXXXXxxxxxXXXXXxxxxx1'
63+
)
64+
}
65+
})
66+
.done(console.log)
67+
.fail(console.error)
68+
```
69+
70+
## 🚀 Deploy
71+
72+
You can easily deploy this function to [now](https://now.sh).
73+
74+
_Contact [Adam Grohs](https://www.linkedin.com/in/adamgrohs/) @ [Particular.](https://uniquelyparticular.com) for any questions._

jest.config.js

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
module.exports = {
2+
roots: ['<rootDir>/src', '<rootDir>/tests', '<rootDir>/spec'],
3+
transform: {
4+
'^.+\\.ts(x)?$': 'ts-jest'
5+
},
6+
verbose: true
7+
}

now.json

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"name": "demo-micro-cors-http-proxy",
3+
"alias": "particular-demo-micro-cors-http-proxy.now.sh",
4+
"env": {
5+
"NODE_ENV": "production",
6+
"PROXY_PREFIX": "@demo-proxy-prefix",
7+
"PROXY_REFERER_WHITELIST": "@demo-proxy-referer-whitelist",
8+
"PROXY_DESTINATION_WHITELIST": "@demo-proxy-destination-whitelist"
9+
},
10+
"routes": [{ "src": "/(.*)", "dest": "/src" }],
11+
"builds": [
12+
{
13+
"src": "src/*.js",
14+
"use": "@now/node"
15+
}
16+
]
17+
}

0 commit comments

Comments
 (0)