Skip to content

martinkr/corsify

Repository files navigation

corsify Build Status

A tiny transparent proxy. The benefit: it adds the CORS-headers! Why? It prevents Cross Domain Errors.

Try it: http://corsify.me

CORS-i-fy? What is this all about?

Cross-origin resource sharing (CORS) is a mechanism that allows restricted resources (e.g. fonts) on a web page to be requested from another domain outside the domain from which the resource originated. https://en.wikipedia.org/wiki/Cross-origin_resource_sharing

Wait… What?!

Your script from http://rebel-mother.surge.sh makes an AJAX-request to http://shaky-library.surge.sh.
You see the infamous "XMLHttpRequest cannot load http://shaky-library.surge.sh. Origin http://rebel-mother.surge.sh is not allowed by Access-Control-Allow-Origin." error message.

corsify to the rescue!

Change your AJAX-Request from http://shaky-library.surge.sh to http://localhost:3001/http://shaky-library.surge.sh. Et voilá: no more errors.

So simple?

For now: yes.

Roll our own!

$ git clone https://github.com/martinkr/corsify.git the repository and fire up your own local instance with docker or plain node.js.

With the included Dockerfile

Fast and clean. No additional files on your machine.

  • Build the image: $ docker build -t corsify:latest .
  • Start the container: $ docker run -p 3001:3000 corsify:latest
  • Go to: http://localhost:3001

Uses alpine:3.6 and node:8.4.0.

Directly on your machine:

Fast and easy, but all those node_modules…

  • Install dependencies $ npm install or $ yarn
  • Build the files and start server $ npm start or $ yarn start
  • Go to: http://localhost:3000

Requires nodejs. Recomended: v8.4.0, but it might work with older versions too.

Tech Stack

  • ECMAScript 2015 on nodejs v8.4.0
  • Rendering Mustache v2.3.0 templates
  • CSS 3 piped through postcss-cli v4.1.1 with cssnano v3.10.0 and cssnano-preset-advanced v4.0.0-rc.2,
  • Running on express`v4.14.1
  • With forever v0.15.3
  • And gzip compression v1.7.0
  • 100% code coverage using mocha v3.5.2, chai v4.1.2, supertest v3.0.0 and "nyc 11.2.1",

Resources

License

Licensed under the MIT license.

Copyright (c) 2016 - 2021 Martin Krause github@mkrause.info http://martinkr.github.io