Skip to content

Instantly share code, notes, and snippets.

@Erisa
Last active December 24, 2020 02:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Erisa/0342a447cf98032df3b334eeb88428ac to your computer and use it in GitHub Desktop.
Save Erisa/0342a447cf98032df3b334eeb88428ac to your computer and use it in GitHub Desktop.
A small wrapper around Cloudflared that creates a tunnel based on the given local and remote(optional) endpoints.
###########################################################################
# A small wrapper around Cloudflared that creates #
# a tunnel based on the given local and remote(optional) endpoints. #
# License: https://unlicense.org/ #
###########################################################################
## Config
# Under Windows+WSL you'll want to use .exe here.
# Since that's what I use personally it's the default.
# Remove the '.exe' extension to use your native Linux cloudflared binary.
cloudflared_bin = "cloudflared.exe"
# (Or if you're feeling in an extra spicy mood, change it to "docker run --network host erisamoe/cloudflared")
# (But I don't really recommend that)
## End of config
## Actual code below.
# Just some small debug.
# Stole from https://github.com/askn/crystal-by-example/blob/master/command-line-args/argv.cr
ARGV.each_with_index {|arg, i| puts "Argument #{i}: #{arg}"}
# This used to error but then I had an EXCEPTIONAl idea.
if ARGV.size < 1
puts "warn: I need at least one argument to do anything useful!"
puts "warn: Defaulting to a test Hello World server."
sleep 1
local = "--hello-world"
else
local = "--url \'#{ARGV[0]}\'"
end
remote = ARGV[1] unless ARGV.size < 2
if remote
`#{ENV["SHELL"]} -c '#{cloudflared_bin} --hostname \'#{remote}\' --url \'#{local}\''`
else
`#{ENV["SHELL"]} -c '#{cloudflared_bin} \'#{local}\''`
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment