Skip to content

Commit

Permalink
Deploy testcab/cors-anywhere
Browse files Browse the repository at this point in the history
  • Loading branch information
davidyuk committed May 8, 2023
1 parent bf6fd69 commit 3b8fba5
Show file tree
Hide file tree
Showing 6 changed files with 110 additions and 241 deletions.
112 changes: 0 additions & 112 deletions .github/workflows/prod-docker.yml

This file was deleted.

19 changes: 0 additions & 19 deletions .github/workflows/test.yml

This file was deleted.

30 changes: 8 additions & 22 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,24 +1,10 @@
FROM node:18-alpine as aepp-aepp-base-build
WORKDIR /app
RUN apk add make g++ python3 git
FROM node:14-alpine

ADD package*.json ./
# TODO: remove --legacy-peer-deps after updating dependencies
RUN npm ci --legacy-peer-deps
ENV NODE_ENV=production
ENV NODE_PATH=/usr/local/lib/node_modules
ARG version=latest
RUN npm install -g cors-anywhere@$version
COPY server.js .
CMD ["node", "server.js"]

COPY . .

ARG VUE_APP_NETWORK_NAME
ARG VUE_APP_NODE_URL
ARG VUE_APP_MDW_URL
ARG VUE_APP_EXPLORER_URL
ARG VUE_APP_COMPILER_URL
ARG VUE_APP_REMOTE_CONNECTION_BACKEND_URL

# TODO: remove legacy openssl after updating @vue/cli
RUN NODE_OPTIONS=--openssl-legacy-provider npm run build

FROM nginx:1.24-alpine
COPY ./nginx/nginx.conf /etc/nginx/nginx.conf
COPY ./nginx/default.conf /etc/nginx/conf.d/default.conf
COPY --from=aepp-aepp-base-build /app/dist /usr/share/nginx/html
EXPOSE 80
29 changes: 17 additions & 12 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
ISC License
Copyright 2019 test.cab <[email protected]>

Copyright (c) 2017, aeternity developers
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:

Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
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" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS 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.
99 changes: 23 additions & 76 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,91 +1,38 @@
# Base æpp [![Build Status](https://api.travis-ci.org/aeternity/aepp-base.svg?branch=develop)](https://travis-ci.org/aeternity/aepp-base/branches)
# testcab/cors-anywhere

## How to get the Base æpp
[![docker build automated](https://img.shields.io/docker/cloud/automated/testcab/cors-anywhere.svg)](https://hub.docker.com/r/testcab/cors-anywhere "testcab/cors-anywhere")
[![](https://images.microbadger.com/badges/image/testcab/cors-anywhere.svg)](https://microbadger.com/images/testcab/cors-anywhere "testcab/cors-anywhere")

* [Google Play](https://play.google.com/store/apps/details?id=com.aeternity.base)
* [App Store](https://apps.apple.com/app/base-æpp-wallet/id1458655724)
* [Web version](https://base.aepps.com/)
The docker image for [cors-anywhere](https://github.com/Rob--W/cors-anywhere).

Also join our [Telegram channel](https://t.me/aeppbase) and our [Forum](https://forum.aeternity.com/t/base-aepp-wallet-we-would-like-your-feedback/3387).

## Build Setup
### Run

```bash
# install dependencies
npm install

# serve with hot reload at http://localhost:8080/
npm run serve

# serve with hot reload at https://localhost:8080/
npm run serve -- --https

# run on android emulator or device
npm run serve:android

# run on ios emulator
npm run serve:ios

# build for production with minification
npm run build

# build for production and view the bundle analyzer report
npm run build -- --report

# generate resources for cordova
npm run gen:cordova-resources

# build for cordova
npm run build:cordova

# build an app file
npm run build:ios

# build an apk file
npm run build:android

# run unit tests
npm run test:unit

# run e2e tests
npm run test:e2e

# run all tests
npm test
```
docker run --rm testcab/cors-anywhere
```


## Contributing
### Supported tags and respective `Dockerfile` links

We use the [gitflow](https://danielkummer.github.io/git-flow-cheatsheet/) workflow [this is also helpful](https://gist.github.com/JamesMGreene/cdd0ac49f90c987e45ac).
* Development of features happens in branches made from **develop** called feature/<the-feature> like feature/show-token-balance.
* When development is finished a pull request to **develop** is created. At least one person has to review the PR and when everything is fine the PR gets merged.
* The develop branch gets deployed to the [stage environment](https://stage-identity.aepps.com) by travis.
* To make a new release create a release branch called release/vX.X.X, also bump the version number in package.json in this branch.
* Create a PR to master which then also has to be accepted.
* Create a tag for this version and push the tag.
* Also merge back the changes (like the version bump) into develop.
* The master branch has to be deployed to the [production environment](https://base.aepps.com/) manually.
* [`0.4.4`, `latest`](https://github.com/testcab/docker-cors-anywhere/blob/master/Dockerfile)
* [`0.4.3`](https://github.com/testcab/docker-cors-anywhere/blob/0.4.3/Dockerfile)

## Deployment

We have a stage (develop) and a production (master) branch and environments where these branches will be deployed to.
* [stage environment](https://stage-identity.aepps.com)
* [production environment](https://base.aepps.com/)
### Envirionment Variables

### stage
* Is used to see changes to the code in effect in a "real" environment without the fear of breaking the production environment.
Env | Default | Description
---- | ------- | -----------
PORT | 8080 | Server listening port
KEY | | Content or filename of TLS Key
CERT | | Content or filename of TLS Certificate
CORSANYWHERE_BLACKLIST | | If set, requests whose origin is listed are blocked.<br>Comma separated. Example: `https://abuse.example.com,http://abuse.example.com`
CORSANYWHERE_WHITELIST | | If set, requests whose origin is not listed are blocked.<br>If this list is empty, all origins are allowed.<br>Comma separated. Example: `https://good.example.com,http://good.example.com`
CORSANYWHERE_RATELIMIT | | Format: `<max requests per period> <period in minutes> <non-ratelimited hosts>`<br>For example, to blacklist abuse.example.com and rate-limit everything to 50 requests per 3 minutes, except for my.example.com and my2.example.com (which may be unlimited), use:<br>`50 3 my.example.com my2.example.com`

### production
* Is the production environment, code lives in the "master" branch.

### other branches
* Every branch is auto-deployed on https://`branch-name`.origin.aepps.com/, with each `/`, `.` symbol in a branch name replaced by `-`.
## LICENSE

### unsigned .apk and .app file
* Find `aetenity.app.tar.gz` file in the [latest release](https://github.com/aeternity/aepp-base/releases/latest) or download corresponding
version from a branch https://`branch-name`.origin.aepps.com/aetenity.app.tar.gz
* Find `aeternity.apk` file in the [latest release](https://github.com/aeternity/aepp-base/releases/latest) or download corresponding
version from a branch https://`branch-name`.origin.aepps.com/aeternity.apk
This repository is licensed under [MIT](LICENSE).

### bundle analyzer report
* Get bundle analyzer report on each domain by adding /report.html. Example [https://stage-identity.aepps.com/report.html](https://stage-identity.aepps.com/report.html).
[cors-anywhere](https://github.com/Rob--W/cors-anywhere#license) is `Copyright (C) 2013 - 2016 Rob Wu [email protected]`
62 changes: 62 additions & 0 deletions server.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
var fs = require('fs')

// Listen on a specific host via the HOST environment variable
var host = process.env.HOST || '0.0.0.0';
// Listen on a specific port via the PORT environment variable
var port = process.env.PORT || 80;

// Grab the blacklist from the command-line so that we can update the blacklist without deploying
// again. CORS Anywhere is open by design, and this blacklist is not used, except for countering
// immediate abuse (e.g. denial of service). If you want to block all origins except for some,
// use originWhitelist instead.
var originBlacklist = parseEnvList(process.env.CORSANYWHERE_BLACKLIST);
var originWhitelist = parseEnvList(process.env.CORSANYWHERE_WHITELIST);
function parseEnvList(env) {
if (!env) {
return [];
}
return env.split(',');
}

// Set up rate-limiting to avoid abuse of the public CORS Anywhere server.
var checkRateLimit = require('cors-anywhere/lib/rate-limit')(process.env.CORSANYWHERE_RATELIMIT);

if (process.env.KEY || process.env.CERT) {
var httpsOptions = {
key: readTLSContent(process.env.KEY),
cert: readTLSContent(process.env.CERT),
};
}

function readTLSContent(tls) {
if (tls.startsWith('-----')) {
return tls
} else {
return fs.readFileSync(tls);
};
}

var cors_proxy = require('cors-anywhere');
cors_proxy.createServer({
originBlacklist: originBlacklist,
originWhitelist: originWhitelist,
requireHeader: ['origin', 'x-requested-with'],
checkRateLimit: checkRateLimit,
removeHeaders: [
'cookie',
'cookie2',
// Strip Heroku-specific headers
'x-heroku-queue-wait-time',
'x-heroku-queue-depth',
'x-heroku-dynos-in-use',
'x-request-start',
],
redirectSameOrigin: true,
httpProxyOptions: {
// Do not add X-Forwarded-For, etc. headers, because Heroku already adds it.
xfwd: false,
},
httpsOptions: httpsOptions,
}).listen(port, host, function() {
console.log('Running CORS Anywhere on ' + host + ':' + port);
});

0 comments on commit 3b8fba5

Please sign in to comment.