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

Commit

Permalink
initial import
Browse files Browse the repository at this point in the history
  • Loading branch information
Adam Grohs authored and Adam Grohs committed May 2, 2019
1 parent db00a14 commit 38e32e9
Show file tree
Hide file tree
Showing 17 changed files with 18,419 additions and 1 deletion.
47 changes: 47 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
version: 2
jobs:
build:
docker:
- image: 'circleci/node:lts'
steps:
- checkout
- run: yarn clean-install
- save_cache:
paths:
- node_modules
key: micro-cors-http-proxy-{{ checksum "package.json" }}
test:
docker:
- image: 'circleci/node:lts'
steps:
- checkout
- restore_cache:
keys:
- micro-cors-http-proxy-{{ checksum "package.json" }}
- run: yarn clean-install
- run: yarn test
release:
docker:
- image: 'circleci/node:lts'
steps:
- checkout
- restore_cache:
keys:
- micro-cors-http-proxy-{{ checksum "package.json" }}
- run: yarn clean-install
- run: npx semantic-release
workflows:
version: 2
build_test_release:
jobs:
- build
- test:
requires:
- build
- release:
filters:
branches:
only:
- master
requires:
- test
40 changes: 40 additions & 0 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
---
name: Bug report
about: Create a report to help us improve
title: ''
labels: ''
assignees: ''
---

**Describe the bug**
A clear and concise description of what the bug is.

**To Reproduce**
Steps to reproduce the behavior:

1. Go to '...'
2. Click on '....'
3. Scroll down to '....'
4. See error

**Expected behavior**
A clear and concise description of what you expected to happen.

**Screenshots**
If applicable, add screenshots to help explain your problem.

**Desktop (please complete the following information):**

- OS: [e.g. iOS]
- Browser [e.g. chrome, safari]
- Version [e.g. 22]

**Smartphone (please complete the following information):**

- Device: [e.g. iPhone6]
- OS: [e.g. iOS8.1]
- Browser [e.g. stock browser, safari]
- Version [e.g. 22]

**Additional context**
Add any other context about the problem here.
19 changes: 19 additions & 0 deletions .github/ISSUE_TEMPLATE/feature_request.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
name: Feature request
about: Suggest an idea for this project
title: ''
labels: ''
assignees: ''
---

**Is your feature request related to a problem? Please describe.**
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

**Describe the solution you'd like**
A clear and concise description of what you want to happen.

**Describe alternatives you've considered**
A clear and concise description of any alternative solutions or features you've considered.

**Additional context**
Add any other context or screenshots about the feature request here.
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# dependencies
node_modules

# misc
.env
*.log
3 changes: 3 additions & 0 deletions .nowignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*.test.*
*.spec.*
/__tests__/
5 changes: 5 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"singleQuote": true,
"semi": false,
"trailingComma": "none"
}
8 changes: 8 additions & 0 deletions .whitesource
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
##########################################################
#### WhiteSource Integration configuration file ####
##########################################################

# Configuration #
#---------------#
ws.repo.scan=true
vulnerable.check.run.conclusion.level=failure
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2019-2025 UNIQUELY PARTICULAR LLC and Adam Grohs

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
75 changes: 74 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,74 @@
# micro-http-proxy
# @particular./micro-cors-http-proxy

[![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)

> 🎮 Minimal HTTP Proxy implementation to support secure whitelisting and CORS
Built with [Micro](https://github.com/zeit/micro)! 🤩

## 🛠 Setup

Create a `.env` at the project root with the following credentials:

```dosini
PROXY_PREFIX=proxy
PROXY_REFERER_WHITELIST=localhost,*.zendesk.com,*.myshopify.com,*.now.sh
PROXY_DESTINATION_WHITELIST=api.stripe.com,api.goshippo.com,api.shipengine.com,api.moltin.com,*.myshopify.com,*.salesforce.com,*.demandware.net
```

`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`)

`PROXY_REFERER_WHITELIST` is a comma separated list of patterns to match against the incoming requests 'Referer' header (ex. `localhost,*.myawesomesite.com,*.now.sh`)
_(and yes, 'REFERER' is intentionally misspelled to match the http header! 😉)_

`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`)

## 📦 Package

Run the following command to build the app

```bash
yarn install
```

Start the development server

```bash
yarn dev
```

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.

## ⛽️ Usage

To send requests to the proxy, the calling implementation should use `encodeURIComponent` to encode the portion of the URI after the `PROXY_PREFIX`.

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`)

Sample call using [jQuery.get()](https://api.jquery.com/jquery.get/) below:

```js
const sampleEndpoint = `https://12345678.ngrok.io//proxy/${encodeURIComponent(
'https://23456789.myshopify.com/admin/customers.json'
)}`

$.ajax({
url: sampleEndpoint,
type: 'GET',
corse: true,
beforeSend: xhr => {
xhr.setRequestHeader(
'X-Shopify-Access-Token',
'1XXXXXxxxxxXXXXXxxxxxXXXXXxxxxx1'
)
}
})
.done(console.log)
.fail(console.error)
```

## 🚀 Deploy

You can easily deploy this function to [now](https://now.sh).

_Contact [Adam Grohs](https://www.linkedin.com/in/adamgrohs/) @ [Particular.](https://uniquelyparticular.com) for any questions._
7 changes: 7 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module.exports = {
roots: ['<rootDir>/src', '<rootDir>/tests', '<rootDir>/spec'],
transform: {
'^.+\\.ts(x)?$': 'ts-jest'
},
verbose: true
}
17 changes: 17 additions & 0 deletions now.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"name": "demo-micro-cors-http-proxy",
"alias": "particular-demo-micro-cors-http-proxy.now.sh",
"env": {
"NODE_ENV": "production",
"PROXY_PREFIX": "@demo-proxy-prefix",
"PROXY_REFERER_WHITELIST": "@demo-proxy-referer-whitelist",
"PROXY_DESTINATION_WHITELIST": "@demo-proxy-destination-whitelist"
},
"routes": [{ "src": "/(.*)", "dest": "/src" }],
"builds": [
{
"src": "src/*.js",
"use": "@now/node"
}
]
}
Loading

0 comments on commit 38e32e9

Please sign in to comment.