Forums

Do we really need two separate web apps, one for each domain?

I have my own domain, but I also want to accept traffic at the original my_username.pythonanywhere.com . Do I really need to have two separate web apps to do this? I find it takes up a portion of my allowed memory and it also makes me have to look at two places (logfiles, configuration) to find any issues with my code.

At the moment, you do. We realise that it's a pain and we're trying to work out ways to change it without making web app configuration much more difficult for users.

edit: nevermind

I suppose the more obvious way would be to disconnect the two concepts - you have a record of a web app, and a record of a domain, and the web interface effectively allows a many-to-one mapping from domain to web app.

To avoid complicating this for most users, I guess you could have a "new domain" wizard which creates new instances of both and hooks them together, but I can certainly appreciate that this still exposes potential complexity to users and potentially increases support load.

It looks like we also need a separate application for each subdomain... Unless there is a workaround. Is there?

The server_name directive in nginx supports wildcards (such as *.example.com), but it appears that the PA web app commissioning process doesn't currently support this. It fails with the error "Sorry, there was an error connecting to the server." so I wonder if it's attempting to do a DNS lookup on the name specified (which of course will fail for a wildcard).

Anyway, perhaps this might be a useful feature for the PA devs to consider if it's easy to implement (given that nginx supports it already), but there may be other issues which make it much more difficult that it first appears.

The current situation is way too inflexible.

I had the same issue, because I used to host my site at harry.pythonanywhere.com, and then I moved to my own domain. I still wanted the old links to work. But, I definitely don't want to run two copies of the same source code. Apart from the hassles you mention, it's bad for your pagerank to run the same site on two domains. What you really want is redirects. So I built a small flask app that would just redirect everything to the new web app:

from flask import Flask, redirect

app = Flask(__name__)

@app.route('/', defaults={'path': ''})
@app.route('/<path:path>')
def redirect_any(path):
    return redirect('http://www.tdd-django-tutorial.com/' + path)

Takes up almost none of the "allowed memory", and it's actually better than having the same site served at two domains.

Which is not to say we shouldn't split out web apps and domains one day...