Skip to content

Instantly share code, notes, and snippets.

@rayantony
Last active August 29, 2016 03:31
Show Gist options
  • Select an option

  • Save rayantony/1b450cd61a3b96d22f4c47d5b7b53fa1 to your computer and use it in GitHub Desktop.

Select an option

Save rayantony/1b450cd61a3b96d22f4c47d5b7b53fa1 to your computer and use it in GitHub Desktop.
Simple Github Proxy

Simple Proxy Server

For hotlinking scripts and css files directly from Github Raw URLs simply run and add the final url into your <script> or <link> tags

example:

<script charset="UTF-8" crossorigin="anonymous" src="http://[].runnablecodesnippets.com/?link=https://gist.github.com/rayantony/2fa7ed9ab778b86819a73dcf3e9a4e6a/xtras.js"></script>

It runs this server

if this doesn't work, you can restart it here then place this new link where the old one was:

simple:

http://[NEW_RUNNABLE_URL].runnablecodesnippets.com/?link=https://gist.github.com/rayantony/2fa7ed9ab778b86819a73dcf3e9a4e6a/xtras.js

Proxy from Stack Overflow

By Ray Anthony twitter Rayrc WebMX Group not really licensed licensed with One World License

<?php
###################################################################################################################
#
# This script can take two URL variables
#
# "type"
# OPTIONAL
# STRING
# Sets the type of file that is output
#
# "link"
# REQUIRED
# STRING
# The link to grab and output through this proxy script
#
###################################################################################################################
# First we need to set the headers for the output file
# So check to see if the type is specified first and if so, then set according to what is being requested
if(isset($_GET['type']) && $_GET['type'] != ''){
switch($_GET['type']){
case 'css':
header('Content-Type: text/css');
break;
case 'js':
header('Content-Type: text/javascript');
break;
case 'json':
header('Content-Type: application/json');
break;
case 'rss':
header('Content-Type: application/rss+xml; charset=ISO-8859-1');
break;
case 'xml':
header('Content-Type: text/xml');
break;
default:
header('Content-Type: text/plain');
break;
}
# Otherwise, try and determine what file type should be output by the file extension from the link
}else{
# See if we can find a file type in the link specified and set the headers accordingly
# If css file extension is found, then set the headers to css format
if(strstr($_GET['link'], '.css') != FALSE){
header('Content-Type: text/css');
# If javascript file extension is found, then set the headers to javascript format
}elseif(strstr($_GET['link'], '.js') != FALSE){
header('Content-Type: text/javascript');
# If json file extension is found, then set the headers to json format
}elseif(strstr($_GET['link'], '.json') != FALSE){
header('Content-Type: application/json');
# If rss file extension is found, then set the headers to rss format
}elseif(strstr($_GET['link'], '.rss') != FALSE){
header('Content-Type: application/rss+xml; charset=ISO-8859-1');
# If css xml extension is found, then set the headers to xml format
}elseif(strstr($_GET['link'], '.xml') != FALSE){
header('Content-Type: text/xml');
# If we still haven't found a suitable file extension, then just set the headers to plain text format
}else{
header('Content-Type: text/plain');
}
}
# Now get the contents of our page we're wanting
$contents = file_get_contents($_GET['link']);
# And finally, spit everything out
echo $contents;
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment