-1

I have a Flask project and would like to integrate some third-party service into it, for example a Wordpress blog (what is written in PHP and can't be integrated into a Flask project). That service can have a subdomain on theirs or on our hosting. But the idea is to organize this service as a subfolder of my project.

I know in ASP.Net it's easy to create a virtual directory and assign the whole project that can be hosted anywhere. But I don't know if it's possible to do it with Flask and how to do that.

To summarize:

www.myproject.com/blog should actually point to blog.myproject.com or myproject.wordpress.com

It's not just a route in the same project!

The third party service is hosted completely separately and has nothing to do with my service, it's even may be written in some other language or framework.

PLEASE do not mark this question as duplicate of Add a prefix to all Flask routes, it has nothing to do with it.

mimic
  • 4,897
  • 7
  • 54
  • 93

1 Answers1

4

Flask can do this, but it will be very ugly and hard. As you need to redirect all requests to /blog/* to upstream blog.project.com/*, and return the result to user. That should be something like:

@app.route('/blog/<sub_request>')
def redirect_to_blog(sub_request):
    res = requests.get(urljoin(blog_base, sub_request))
    return res.content

Generally, you shouldn't even think about this. This is actually a very common scenario for nginx. You should use nginx as your reverse proxy server and manage all sub-domains. In that case, you can easily achieve what you want.

Or let's say this is also a very common scenario for apache2. Which is the server of your Wordpress blog. You should use apache2 to manage your flask project. Instead of using flask project to manage apache2 server.

Sraw
  • 18,892
  • 11
  • 54
  • 87