I have a heroku app using python and flask. It currently serves a whole domain and all endpoints.
http://*.domain.com/* -> one heroku app
I like to explore different languages and frameworks, and want to rewrite different sections of the website. Is that possible?
It would work out to something like
http://www.domain.com/python-stuff (a python/flask app)
http://www.domain.com/ruby-stuff (a ruby/sinatra app)
http://www.domain.com/java-play-stuff (a java/playframework app)
All I can see is possibly having one app that handles www and all subdirs, and redirects to a different subdomain instead.
http://www.domain.com/ruby-stuff -> http://ruby-stuff.domain.com/ruby-stuff
http://www.domain.com/java-play-stuff -> http://java-play-stuff.domain.com/java-play-stuff
http://www.domain.com/{{ everything else }} -> the original python flask app
I don't want to do this because then I'd have to restructure all of my openid users to point to www.domain.com for their seed url explicitly instead of relying that all logins are coming from the same subdomain. (Among other reasons like cookies (well that's related to open id also)
Thoughts?
Setup an Amazon CloudFront distribution and have it map specific paths to different origin servers.
Related
I have been scouring the web to help me find the best way to do this and haven't found a proper answer.
I want to create a single web app with flask that contains multiple dashboard pages. The app needs to run on a different subdomain for every user–the user being a different business eg. client1.myapp.com. The functionality will be largely shared across the different clients and thus subdomains. However, I want to define a config file that will look something like this:
client1 = {"show_graph1":True, "show_graph2":False}
client2 = {"show_graph1":False, "show_graph2":True}
So the app would be hosted on a single aws elastic beanstalk instance and serve all these subdomains. The flow would be:
Client1 goes on unique url client1.myapp.com
Client1 logs in to myapp
Myapp recognises that it is on subdomain for client1, fetches the configuration from the config file and configures the dashboard pages accordingly.
I have looked into flask blueprints and from what I've understood this would be the best way to set this up, but I am not clear on how I would dynamically fetch and implement the configuration nor on how will flask simultaneously serve all subdomains at once.
What would be the best application structure to setup this use case with flask?
Any help would be much appreciated.
If your flask app is listening for all connections, you can point as many domains to it as you like. Then in your dashboard views, or globally if you prefer, you can get your configuration based on what domain the app was requested through.
For example:
#app.before_request
def before_request_func():
domain = request.host
g.client_config = get_client_config(domain)
I want advice on how to do the following:
On the same server, I want to have two apps. One WordPress app and one Python app. At the same time, I want the root of my domain to be a static landing page.
Url structure I want to achieve:
example.com/ => static landing page
example.com/tickets => wordpress
example.com/pythonapp => python app
I have never done something like this before and searching for solutions didn't help.
Is it even possible?
Is it better to use subdomains?
Is it better to use different servers?
How should I approach this?
Thanks in advance!
Yes, it is possible with php rewrite engine.
Internally the wordpress app may have some random URL, but you can modify it and show as whatever you wanted it to the users.
once have a look at this
https://www.addedbytes.com/blog/url-rewriting-for-beginners
It depends on the webserver you want to use. Let's go with apache as it is one of the most used web servers on the internet.
You install your wordpress installation into the /tickets subdirectory and install word-press as you normally would. This should install wordpress into the subdirectory.
Configure your Python-WSGI App with this configuration:
WSGIScriptAlias /pythonapp /var/www/path/to/my/wsgi.py
I have two django application which are on same server on port 80 and 9002. i.e. urls are www.abc.com and www.abc.com:9002
Both share same database postgresql for authentication. I want to share the share the session data between them so that user logged in to one application can log in automatically in another application.
I read these answers : Multiple Django apps, shared authentication and How to get distinct Django apps on same subdomain to share session cookie?
And did this in my both django application:
Used the same secret key in both.
Added these lines:
SESSION_ENGINE = 'django.contrib.sessions.backends.signed_cookies'
SESSION_COOKIE_NAME = 'abc'
SESSION_COOKIE_DOMAIN = '.abc.com'
But still I am unable to achieve the purpose.
How to share the session cookie between two django apps so that i can have shared authentication?
Other than you have to apply these settings to both applications,
the only thing missing with your approach is the SESSION_COOKIE_DOMAIN.
You set it to '.abc.com', which means it will work if your app has domain name: www.abc.com and somesubdomain.abc.com.
But your second app in this case www.abc.com:9002, by including the port it doesn't share the same TLD with www.abc.com. So, django thinks www.abc.com:9002 and www.abc.com are very different domain and not from the same root .abc.com.
If I'm working on this, there are several possible approach:
Combine both app into one single root django app. Django app were modular anyway, so you could create one single ROOT_URL_CONF and DJANGO_SETTINGS_MODULE to specify how these two apps works in the same domain. You could, for example, append a different prefix url for each app.
You use load balancer, or reverse proxy, such as nginx or haproxy to assign different subdomain for each app, then deploy each app in a different port. Let's say, the end result is you have the first django app deployed on first.abc.com and the second app in second.abc.com (All with port 80 in the frontend), then it will share the same session. Just remember that in the backend you need to assign the actual port that the app uses.
Additional notes from mine. In production settings, you also want to add ALLOWED_HOSTS settings and include .abc.com in the list.
I have a simple portfolio website with some html and css files in the root directory of the site hosted by Dreamhost. I also have a Django app that I'd like to place in a subdomain of this same website. However, Heroku will be serving the django app. I'm confused about how to organize and configure the whole portfolio/django website. How would the system work using two different hosts? Should I integrate the static portfolio site into the django project? Or do I keep them completely seperate and have them live on their own servers? Sorry if my question doesn't make sense. I'm very confused.
As far as the internet's concerned, a subdomain is a completely separate website. You can point a subdomain at whatever address you like; the internet doesn't care that it's a completely separate host. You can host your system however you like: both on Dreamhost, both on Heroku, or one on each. The latter setup is the most complex, so we'll walk through that one here.
Let's say your site is example.com and you want the portfolio site to be portfolio.example.com. If your app's running on Heroku, it'll have a name similar to yourportfolio.herokuapp.com. So we need to do two things: tell Heroku that your app is served from portfolio.example.com, and tell the DNS system to point from your subdomain from Heroku.
Pointing the subdomain to Heroku
Presuming your domain name is hosted on Dreamhost, go to the Domains section of the control panel, then Manage Domains. Under example.com is a link called DNS. You need to add a custom CNAME record; set name to portfolio, type to CNAME, and value to yourportfolio.herokuapp.com.. CNAMEs are a way of setting up aliases on the web; they mean "this site is also known as foo".
Telling Heroku to serve your app
Within your Heroku project, run heroku domains:add portfolio.example.com.
Heroku has documentation about subdomains here, which is a useful overview of the process as well as giving details of more complex setups.
I am trying to mock-up an API and am using separate apps within Django to represent different web services. I would like App A to take in a link that corresponds to App B and parse the json response.
Is there a way to dynamically construct the url to App B so that I can test the code in development and not change to much before going into production? The problem is that I can't use localhost as part of a link.
I am currently using urllib, but eventually I would like to do something less hacky and better fitting with the web services REST paradigm.
You could do something like
if settings.DEBUG:
other = "localhost"
else:
other = "somehost"
and use other to build the external URL. Generally you code in DEBUG mode and deploy in non-DEBUG mode. settings.DEBUG is a 'standard' Django thing.
By "separate apps within Django" do you mean separate applications with a common settings? That is to say, two applications within the same Django site (or project)?
If so, the {% url %} tag will generate a proper absolute URL to any of the apps listed in the settings file.
If there are separate Django servers with separate settings, you have the standard internet problem of URI design. Your URI's can be consistent with only the hostname changing.
- http://localhost/some/path - development
- http://123.45.67.78/some/path - someone's laptop who's running a server for testing
- http://qa.mysite.com/some/path - QA
- http://www.mysite.com/some/path - production
You never need to provide the host information, so all of your links are <A HREF="/some/path/">.
This, generally, works out the best. You have can someone's random laptop being a test server; you can get the IP address using ifconfig.