0

I have been researching this for quite a while and it seems that I cannot get my head around it. I have different ideas but all of them looks like they are not the right one to solve this problem.

I have an application in flask that does different things like for example:

  • loading an image (user profile image)
  • calling APIs (to perform specific tasks, like for example adding a comment to a forum post)
  • etc.

The way I am doing all of this is by using url_for in this way:

client_info = requests.post(url_for('api.read_comments', _external=True),
                                json={'client_name': client}).json()

So my application is at "https://www.myapp.com/comments" - The "url_for()" in my code will basically generate this url: "https://www.myapp.com/api/read_comments". All comments are then retrieved by my API code.

This works just fine, but what I would like to do is to have the Frontend on "https://www.myapp.com/" but the Backend on "https://backend.myapp.com".

So my question is, how can I make my url_for() as dynamic as possible and able to access content on other subdomains/servers that I own?

Any thoughts? Or additional methods/functions that I should be using? For example all comments will be located at "comments.myapp.com", all my profile details are on "profiles.myapp.com", etc. This is just a general idea on how the system can be setup. Any thoughts?

Thanks a lot and I look forward to hearing from you.

Rob
  • 89
  • 6
  • 'what I would like to do is to have the Frontend on "https://www.myapp.com/" but the Backend on "https://backend.myapp.com"' – why do you want to do this? As you have already found out, you are making life hard for yourself by trying to do this. – ash Jan 06 '19 at 21:34
  • Because I want have the API directly connected with a DB and I do not want the front-end connected with the database. I want to be able to perform database operations only on specific servers and possibly use load balancing for front-end. – Rob Jan 07 '19 at 11:49
  • 1
    If you use subdomain handling on your routes (https://stackoverflow.com/a/11027090/6685140), will calling `url_for` on the route method return a URL with the proper subdomain? – Sam Hollenbach Jan 08 '19 at 08:30
  • Hi Sam, could be a good idea actually. I did not thought about that. Thanks. – Rob Jan 12 '19 at 16:23

0 Answers0