1

I've set up a free account on Google App Engine, and I currently have something like this deployed:

import webapp2

class MainHandler(webapp2.RequestHandler):
    def get(self):
        self.redirect('http://x.x.x.x:9000/')

This works and accomplishes what I was in the basic sense but since it's just issuing a http redirect I don't get my fancy Google Domain name and it ends up being the ip address (and port) of the final server. I am aware of why this happens, but was hoping for a solution that would preserve the domain name (and leave the port hidden).

Normally for something like this, you'd just have a rewrite rule in Apache, but that only works if both URLs are hosted by that same server. When the two servers are different, you'd probably go with some transparent proxy (Squid?), but I don't have a server capable of hosting that (this is for personal use, and though my router is ddwrt, I've had no luck getting squid installed on it).

So is there a python one-liner that let's me proxy to a single address but is smart enough to mangle resource requests and send along any request headers? I've found various solutions for writing proxies in python, but they seem overly complicated because they're intended to be general purpose.

This isn't even easy to google, since the obvious keywords all bring back too many results with only slightly relevant results.

Ying Li
  • 2,500
  • 2
  • 13
  • 37
John O
  • 4,863
  • 8
  • 45
  • 78
  • I'm not sure what you are trying to achieve. Why not host your website directly on GAE? Or, alternatively, why not point the domain directly at wherever the website is actually hosted? – Daniel Roseman Mar 06 '15 at 21:37
  • @DanielRoseman The "website" is the http-ized configuration/monitoring page for an application. I can't host it anywhere, it's just integral. I guess I shouldn't be shy, it's for the Transmission torrent client. – John O Mar 06 '15 at 21:57
  • get GAE to get the resources (urlfetch?), then serve them back to the client? – Paul Collingwood Mar 06 '15 at 22:02
  • @PaulCollingwood Which is my question. Is there a simple or single-line way of doing that? If it is more complicated, I'm pretty sure I'll get it wrong but in a subtle way. I was wondering if this is an already-solved-problem... – John O Mar 06 '15 at 22:28
  • urlfetch is pretty much a one liner. Read the docs and give it a go. However it is not a configuration rule, but python code. You will soon find out if it's too complicated or can't do what you want. (If it's too complicated you might find all solutions are two complicated.) – Tim Hoffman Mar 07 '15 at 03:59
  • @TimHoffman I don't think it could ever be a one-liner, given that any single page fetch is going to want to grab more than one resource. There's always a stylesheet or two, always images, always js. – John O Mar 09 '15 at 18:41

2 Answers2

0

You are looking for a reverse proxy setup. Here is one that I have used before. https://code.google.com/p/bs2grproxy/

miah
  • 10,093
  • 3
  • 21
  • 32
0

You can either setup the DNS to point your domain directly to the IP address OR you can use urlfetch.

However, please keep in mind that urlfetch has quota and limitations [1]. It might not be worth it just to have a "pretty domain/URL".

[1] https://cloud.google.com/appengine/docs/quotas#UrlFetch

Ying Li
  • 2,500
  • 2
  • 13
  • 37