cors-anywhere icon indicating copy to clipboard operation
cors-anywhere copied to clipboard

Add dockerfile to start server in a docker container

Open FuriKuri opened this issue 5 years ago • 10 comments

I've added a simple dockerfile so it is easier to start your own server.

FuriKuri avatar Oct 03 '18 15:10 FuriKuri

Coverage Status

Coverage remained the same at 100.0% when pulling 67f033bf8278b07cb6aba6a57f95cdd592d56de3 on FuriKuri:master into 2ee31471ce3b624b5503bcc9c62fbe6783192c45 on Rob--W:master.

coveralls avatar Oct 03 '18 15:10 coveralls

Thanks for this PR. I'm not merging it because it does not offer critical functionality, but I'll keep the PR open so that others who are looking for an example of using CORS Anywhere in a Docker container.

Rob--W avatar Oct 03 '18 20:10 Rob--W

I like this PR! cors-anywhere exists to be deployed, why not make it easier using a very standard tool (Docker)? I would imagine lots of people coming here end up using Docker to deploy. Just my two cents.

wafisher avatar Dec 02 '18 18:12 wafisher

Merging this PR and setting up automatic builds would help a lot! Right now lots of people are creating their own images with cors-anywhere inside and push it to docker hub. I researched a few of them and looks like I have to build one more :( as they all are user-specific (e.g. https://github.com/psimonov/cors-anywhere/blob/master/app.js#L9)

Having an official cors-anywhere image, I would set up and run an instance e.g. in AWS ECS in a few clicks of the mouse.

@Rob--W please, consider merging this!

Thanks for your work!

RomanHotsiy avatar Mar 25 '19 15:03 RomanHotsiy

Hi, this would be an useful addition because it makes cors-anywhere executable from any non-node server with a single docker run cors-anywhere :)

revolunet avatar Apr 23 '19 06:04 revolunet

hello, dockerfile offers critical functionality for those who need to actually deploy it. docker is today's standard way to deploy stuff.

jiri-jirus avatar May 30 '20 13:05 jiri-jirus

I've added a simple dockerfile so it is easier to start your own server.

I run the cors-anywhere container using your dockerfile,When i run the docker image this is the output i am getting in the browser

This API enables cross-origin requests to anywhere.

Usage:

/               Shows help
/iscorsneeded   This is the only resource on this host which is served without CORS headers.
/<url>          Create a request to <url>, and includes CORS headers in the response.

If the protocol is omitted, it defaults to http (https if port 443 is specified).

Cookies are disabled and stripped from requests.

Redirects are automatically followed. For debugging purposes, each followed redirect results
in the addition of a X-CORS-Redirect-n header, where n starts at 1. These headers are not
accessible by the XMLHttpRequest API.
After 5 redirects, redirects are not followed any more. The redirect response is sent back
to the browser, which can choose to follow the redirect (handled automatically by the browser).

The requested URL is available in the X-Request-URL response header.
The final URL, after following all redirects, is available in the X-Final-URL response header.


To prevent the use of the proxy for casual browsing, the API requires either the Origin
or the X-Requested-With header to be set. To avoid unnecessary preflight (OPTIONS) requests,
it's recommended to not manually set these headers in your code.


Demo          :   https://robwu.nl/cors-anywhere.html
Source code   :   https://github.com/Rob--W/cors-anywhere/
Documentation :   https://github.com/Rob--W/cors-anywhere/#documentation

Is this means,cors-anywhere running successfully in my local ?, If yes please let me know how to test.

Thanks in advance :)

madhav411 avatar Feb 19 '21 06:02 madhav411

@FuriKuri Yes seeing that page means that CORS Anywhere is running. To test it, follow the instructions as shown in that text that you're seeing.

Rob--W avatar Feb 20 '21 18:02 Rob--W

@FuriKuri Yes seeing that page means that CORS Anywhere is running. To test it, follow the instructions as shown in that text that you're seeing.

@Rob--W

Hi, could you help me on this? I deployed cors-anywhere to Azure App Service. When I call this https://corsproxy-execute.azurewebsites.net/https://www.google.com.sg/, for example, instead of going to google, it shows the default texts as below. Am I doing something wrong? Kindly advise.

This API enables cross-origin requests to anywhere.

Usage:

/ Shows help /iscorsneeded This is the only resource on this host which is served without CORS headers. / Create a request to , and includes CORS headers in the response.

If the protocol is omitted, it defaults to http (https if port 443 is specified).

Cookies are disabled and stripped from requests.

Redirects are automatically followed. For debugging purposes, each followed redirect results in the addition of a X-CORS-Redirect-n header, where n starts at 1. These headers are not accessible by the XMLHttpRequest API. After 5 redirects, redirects are not followed any more. The redirect response is sent back to the browser, which can choose to follow the redirect (handled automatically by the browser).

The requested URL is available in the X-Request-URL response header. The final URL, after following all redirects, is available in the X-Final-URL response header.

To prevent the use of the proxy for casual browsing, the API requires either the Origin or the X-Requested-With header to be set. To avoid unnecessary preflight (OPTIONS) requests, it's recommended to not manually set these headers in your code.

Demo : https://robwu.nl/cors-anywhere.html Source code : https://github.com/Rob--W/cors-anywhere/ Documentation : https://github.com/Rob--W/cors-anywhere/#documentation

emerald1000 avatar Feb 25 '21 08:02 emerald1000

I switched long ago from heroku, to fly.io, fly.io DOES allow building from heroku build files, but the Fly Docker image, with Heroku specific stuff, has 400 MBs more userland junk (more heroku specific NPM default node packages, more handy .so files CORS-A and node will never use, and other framework runtimes, IDK, python, php, and friends), in the image (700 MB vs 250 MB), than Node on Docker on Fly. Also the Fly+Heroku public API emulation layer, where fly adds shell scripts and binaries that emulate heroku env vars, in your VM, before launching node, those heroku emulation/heartbeat shell scripts and binaries are added ABOVE your CORS-A node_packages docker layer, causing docker image bloat. I don't remember if Fly+Heroku emulation VM has 1-2 extra no-CPU used processes hanging around, but be a good citizen, and dont use Heroku emulator on Fly. Build times on a github actions push are much faster, if you strip "Heroku Ubuntu" and switch to "node-slim Ubuntu"

.github\workflows\fly.yml

name: Fly Deploy
on:
  push:
    branches:
    - '*'

env:
  FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }}
  NODE_ENV: production

jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - uses: superfly/flyctl-actions/setup-flyctl@master
      - run: flyctl version
      - run: flyctl deploy --remote-only

Dockerfile

# syntax = docker/dockerfile:1

# Adjust NODE_VERSION as desired
ARG NODE_VERSION=18.16.0
FROM node:${NODE_VERSION}-slim as base

LABEL fly_launch_runtime="NodeJS"

# NodeJS app lives here
WORKDIR /app

# Set production environment
ENV NODE_ENV=production


# Throw-away build stage to reduce size of final image
FROM base as build

# Install packages needed to build node modules
RUN apt-get update -qq && \
    apt-get install -y python-is-python3 pkg-config build-essential 

# Install node modules
COPY --link package.json package-lock.json .
RUN npm install

# Copy application code
COPY --link . .



# Final stage for app image
FROM base

# Copy built application
COPY --from=build /app /app

# Start the server by default, this can be overwritten at runtime
CMD [ "npm", "run", "start" ]

.dockerignore

.dockerignore
.eslintignore
.eslintrc
.git
.github
.gitignore
.travis.yml
Dockerfile
README.md
demo.html??????????????????????MAYBE_U_KEEP_THIS_I_DELETE_IT
fly.toml
privkey.pem??????SPECIFIC_MY_FORK
pubcert.pem??????SPECIFIC_MY_FORK
test

fly.toml

# fly.toml file generated for APPNAMEFIXME on 2023-02-08T23:24:03-05:00

app = "APPNAMEFIXME"
primary_region = "ewrREGIONFIXME"
kill_signal = "SIGINT"
kill_timeout = 5

[build]
  [build.args]
    NODE_ENV = "production"

[env]
  PORT = "8080"

[experimental]
  allowed_public_ports = []
  auto_rollback = true
  cmd = []
  entrypoint = []
  exec = []

[processes]
  app = "node server.js"

[[services]]
  http_checks = []
  internal_port = 8080
  processes = ["app"]
  protocol = "tcp"
  script_checks = []
  min_machines_running = 1
  [services.concurrency]
    hard_limit = 25
    soft_limit = 20
    type = "connections"

  [[services.ports]]
    force_https = true
    handlers = ["http"]
    port = 80

  [[services.ports]]
    handlers = ["tls", "http"]
    port = 443

  [services.ports.http_options.response.headers]
    fly-request-id = false
    server = false
    via = false

  [[services.tcp_checks]]
    grace_period = "1s"
    interval = "15s"
    restart_limit = 0
    timeout = "2s"

bulk88 avatar Oct 15 '23 21:10 bulk88