How does one google app engine app serve multiple domains? - google-app-engine

Or can it be done?
For example, I want to help a few friends to setup their shopping cart websites. They have their website domain names already purchased. But I want to pay one google app engine application at www.mywebsite.com, and I want to "forward" their domain to www.mywebsite.com/friend1, www.mywebsite.com/friend2. In this way, I want their customers see their website which could be http://www.friend1.com, but they are actually served by one single app engine application.
In my application, I know how to get the path analyzed so I can go to datastore to serve diffrent pages, html. So the question is just how or can one google app engine be forwarded from different domains. Thanks!

I'm not quite sure what is your exact meaning of "forward", but I try to answer for different situations.
If you want the browser to keep displaying www.friend1.com all the way without ever showing www.mywebsite.com, you should have friend1.com setup as a Google App account, and add their domain into your application (just like you did for your own domain). This way, all traffic to www.friend1.com (or what ever subdomain they pick) goes to your appengine app. And your App should detect the domain of the http request and response accordingly.
If you just want a "redirect"... that means, user goes to www.friend1.com will have their browser auto goes to www.mywebsite.com/friend1 and displaying it in the URL bar , well, just setup one index.html page in www.friend1.com and add meta refresh header in the file. Or use any server side redirect method.

Related

How to redirect a wildcard subdomain in GCP to a static site in a folder in a Google bucket while still displaying the subdomain in the URL?

We want to map subdomains to static sites hosted in folders within a GCP bucket. From a non-technical perspective, this is identical to what Shopify and other website builders do with their sites for trial customers.
For example:
1. Navigate to foo.rootdomain.com
2. Display site stored inside at <Shared Google Bucket>/foo/index.html
3. Continue displaying foo.rootdomain.com in URL address bar
These subdomains/subdirectories will be created on-demand programatically when customers request them. For example, a customer could request "baz.rootdomain.com", and then we will upload their static site to the shared Google bucket's /baz subdirectory. These subdomains should all be SSL'd. We should be able to support tens to hundreds of thousands of these subdomains, all on the same root domain. That is:
abc.rootdomain.com --> <Shared Google Bucket>/abc/index.html
anothersubdomain.rootdomain.com --> <Shared Google Bucket>/anothersubdomain/index.html
foobar.rootdomain.com --> <Shared Google Bucket>/foobar/index.html
<ANY_TEXT>.rootdomain.com --> <Shared Google Bucket>/<ANY_TEXT>/index.html
I started by looking into Google's load balancers and URL maps to handle these, but AFAICT, these can only map to explicit resources rather - so they could be mapped to a backend bucket which redirects to a specific bucket, but couldn't be mapped to a parameterized bucket based on the subdomain. This SO answer explains how to map wildcard routes to specific resources, which doesn't work for this use-case.
I also looked into hosting a service at Google's App Engine and doing routing via dispatch.yaml because subdomains need to be listed out explicitly and there is a limit of 20 routing rules, so we'd need to keep creating them for every 20 subdomains, which wouldn't scale.
It looks like in this question the author had the same problem and was able to solve it by "creating separated VM instance that actually proxying requests to the google bucket". I looked up 'GCP vm proxy requests to google bucket' and wasn't able to figure out what this means, or how to do it. This doc page talks about using proxies to keep files private, which isn't what we're trying to do, and was very confusing to read through in general.
How can we approach this issue?

Problem Mapping a subdomain to an GAE app

I have a GAE app (Aggregate web site) at the url projectname.appspot.com
Now, I bought a domain mydomain.com from LWS and I want to map the subdomain projectname.mydomain.com to projectname.appspot.com
After setting all the required steps suggested by GAE, I'm able to reach my GAE app via projectname.mydomain.com; but, once the page finishes loading, instead of the new url (my hope), the old one (projectname.appspot.com) still displaying in the address bar of my browser.

Serve different app on particular subdomain in multi-tenant system

I have built an flask app hosted in App Engine, have used wildcard subdomain mapping along with namespace support provided App Engine so that app will be served from any subdomain. Its all working fine.
Now, I want to make one of the subdomain, say admin.domain.com to handle some admin related activities. All other subdomain points to normal app.
When un-registered user visits company.domain.com, it should be redirected to admin.domain.com where he will register, once done he will go back automatically to company.domain.com.
How to map a admin app to particular subdomain? Is there anyway to do it using Flask or App Engine? If not possible, how to handle this scenario?
This is the first time I am building such a app.
Thanks..
I'm not sure about the semantics when you use the word 'app'. In strict GAE sense, an apps are completely separate, each with its own billing and datastore etc.
If you strictly want to have the admin app as a separate app, you can't use the wildcard subdomain mapping. You'd have to manually map each subdomain using the App Engine admin settings for mapping domains. You can map the admin.domain.com to your admin app, and manually map your other subdomains to the normal app.
If you're just talking about separate admin functionality that runs in the same app, and you're not strictly set on using admin.domain.com, the best way is probably to use the new modules functionality and create your 'admin' as a separate module and use dispatch.yaml to route to it:
https://developers.google.com/appengine/docs/python/modules/routing
Otherwise, Flask/GAE doesn't really provide any built in mechanism for this. You'd have to do something messy like check the URL in every request handler and act appropriately if it's admin.

Redirecting domain (not google apps) to appengine

I'm building a application that supports different domains. A small CMS that supports different domains.
But what I can't figure out is how to redirect other domains that's outside google apps. I have a domain at google apps, that work's perfectly.
When I create a cname that points at either my appid.appspot.com or www.appsdomain.com it just goes to google.com.
What do I need to do so the other domains point to my appengine application.
..fredrik
You can't just use a cname because google needs to know how to direct the requests through their infrastructure to your app.
You should follow the instructions here: http://code.google.com/appengine/docs/domain.html to set up your name with their infrastructure so that requests to the cname get routed correctly.
Update: You do not have to move your domain to google, only inform them of the names you are going to set up cnames to point to them.
You can do that without a cname.
You need to set up a redirection mechanism of your second domain name. You can do that either by telling your registrar to redirect that url to your Google Apps url (that's how I do it with my registrar, name.com), or you could set up a small [php] script on a server you manage that would receive the queries on the second domain and issue a 301 redirect to your Google Apps domain.
EDIT: It all depends on what you want to do. If you want your app to live at both urls, then this solution will not work. I wrote this in the idea that you want the second url to redirect to your main url, if that's not what you want to do, then issuing redirects won't do the trick.

gwt and dynamic server processing. Do they belong together?

I am eager to build an application with Gwt and App Engine. I'm more familiar with App Engine: creating dynamic html pages with servlets and jsp's. I'm wondering however, if this type of application technology belongs with GWT?
The two examples I can foresee being a problem are login and database retrieval.
For user log-in, my current approach is simple: at the beginning of a servlet, check if the user object exists. If it does, show the page. If it doesn't, redirect to Google's login service. How does this model fit in with GWT? It seems to me that GWT compiles into static html/javascript/css files you place on your server. With this approach, it doesn't seem possible to do any server processing to check for a vlid user before serving the static page (because any user could just bypass the servlet and type the static page url directly).
The other example would be show data from the app engine datastore. If i wanted to create a table which each row being an entry from the data store, I would dynamiclly create the html in a servlet, and do my datastore access there etc, etc. It seems with GWT I would have to serve a container html page, then use ajax to load the database content after the fact?
Maybe GWT isn't right for my type of application, or maybe I'm just thing about web application development the wrong way. Some clarification would be appreciated.
In a over simplified sense, a typical GWT app will work like this:
User navigates to your web page. Their browser uses a static url(s) to download all the javascript, css, and images necessary to run your app.
From now on, every time a user presses a button or otherwise interacts with the page, data is retrieved via an AJAX call. So yes, they might download your app before logging in, but all your security sensitive data would only be returned via an ajax call, giving you the chance to validate their identity however you wish (cookie, user/pass, etc)
This is basically what you describe in your second example about loading data from the datastore. It sounds like you think this is bad for some reason, but you don't say why.

Resources