Skip to content

Instantly share code, notes, and snippets.

@andriitishchenko
Last active November 16, 2022 15:42
Show Gist options
  • Save andriitishchenko/b07d829b787f94cccc4175b69fd700ef to your computer and use it in GitHub Desktop.
Save andriitishchenko/b07d829b787f94cccc4175b69fd700ef to your computer and use it in GitHub Desktop.

http[s] tunnes

Assume webserver at localhost:8080

localhost.run

Will not works for Self-signed certificate

$ ssh -R 80:localhost:8080 [email protected]

Seems using of ssh key allows to generate a static public url:

$ ssh -o "IdentitiesOnly=yes" -i /Users/me/.ssh/id_ed25519 -R 80:localhost:8080 localhost.run

urls looks like https://<random_string>.lhr.life

bore

Works with Self-signed certificate

Seems using the same port allows to generate a static public url

download binary https://github.com/ekzhang/bore/releases

./bore local 8080 --to bore.pub -p [>1024]

urls looks like https://bore.pub:43024

Local server

node

  1. Install http-server with nmp
$ npm install -g http-server

Start server

$ http-server -p 8080 -a 127.0.0.1 <path_to_http_root>
  1. Create private key and pubic cert
$ openssl genrsa 2048 > key.pem
$ openssl req -x509 -days 1000 -new -key key.pem -out cert.pem

Start server with SSL

$ http-server --ssl -c-1 -p 8080 -a 127.0.0.1 <path_to_http_root>

python

requirements.txt

requests
flask

server.py

#!/usr/bin/env python3
# encoding: utf-8

# 
# install deps:
# pip3 install -r requirements.txt
# 
# to start server:
# python3 server.py
# 

import json
import random
from flask import Flask, request, jsonify

app = Flask(__name__)

# ROUTS
@app.route('/',methods=['GET'])
def index():
    return f"Hello world!"


@app.route('/hello/<param_val>',methods=['GET', 'POST'])
def hello(param_val):
    return f"Param = {str(param_val)}"


# ERROR HANDLING

@app.errorhandler(400)
def bad_request(e):
    return '', e.code

@app.errorhandler(404)
def not_found(e):
    return '', e.code 

@app.errorhandler(500)
def server_error(e):
    return '', e.code

# START SERVER

if __name__ == '__main__':
    # http
    app.run(host='0.0.0.0', port=8080,debug=True)
    # https
    # app.run(host='0.0.0.0', port=8080,debug=True,ssl_context='adhoc')
    # or
    # app.run(host='0.0.0.0', port=8080,debug=True,ssl_context=('cert.pem', 'key.pem'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment