forked from paylogic/flask-cdn
-
Notifications
You must be signed in to change notification settings - Fork 0
/
params.json
6 lines (6 loc) · 5.6 KB
/
params.json
1
2
3
4
5
6
{
"name": "Flask-CDN",
"tagline": "Serve the static files in your Flask app from a CDN.",
"body": "# Flask-CDN\r\n\r\n[![Version](https://img.shields.io/pypi/v/flask-cdn.svg)](https://pypi.python.org/pypi/Flask-CDN)\r\n[![Build Status](https://travis-ci.org/libwilliam/flask-cdn.png)](https://travis-ci.org/libwilliam/flask-cdn)\r\n[![Coverage](https://coveralls.io/repos/wichitacode/flask-cdn/badge.svg)](https://coveralls.io/github/wichitacode/flask-cdn)\r\n[![License](https://img.shields.io/pypi/l/flask-cdn.svg)](https://github.com/libwilliam/flask-cdn/blob/master/LICENSE)\r\n\r\nFlask-CDN allows you to easily serve all your [Flask](http://flask.pocoo.org/) application’s static assets from a CDN (like [Amazon Cloudfront](https://aws.amazon.com/cloudfront/)), without having to modify your templates.\r\n\r\n## How it works\r\nFlask-CDN replaces the URLs that Flask’s `flask.url_for()` function would insert into your templates, with URLs that point to your CDN. This makes setting up an origin pull CDN extremely easy.\r\n\r\nInternally, every time `url_for` is called in one of your application’s templates, `flask_cdn.url_for` is instead invoked. If the endpoint provided is deemed to refer to static assets, then the CDN URL for the asset specified in the filename argument is instead returned. Otherwise, `flask_cdn.url_for` passes the call on to `flask.url_for`.\r\n\r\n## Installation\r\nIf you use pip then installation is simply:\r\n```shell\r\n$ pip install flask-cdn\r\n```\r\n\r\nor, if you want the latest github version:\r\n```shell\r\n$ pip install git+git://github.com/wichitacode/flask-cdn.git\r\n```\r\n\r\nYou can also install Flask-CDN via Easy Install:\r\n```shell\r\n$ easy_install flask-cdn\r\n```\r\n\r\n## Dependencies\r\n\r\nThere are no additional dependencies besides Flask itself. Note: Flask-CDN currently only supports applications that use the [jinja2](http://jinja.pocoo.org/docs/) templating system.\r\n\r\n## Using Flask-CDN\r\nFlask-CDN is incredibly simple to use. In order to start serving your Flask application’s assets from Amazon CDN, the first thing to do is let Flask-CDN know about your `flask.Flask` application object.\r\n\r\n```python\r\nfrom flask import Flask\r\nfrom flask.ext.cdn import CDN\r\n\r\napp = Flask(__name__)\r\napp.config['CDN_DOMAIN'] = 'mycdnname.cloudfront.net'\r\nCDN(app)\r\n```\r\n\r\nIn many cases, however, one cannot expect a Flask instance to be ready at import time, and a common pattern is to return a Flask instance from within a function only after other configuration details have been taken care of. In these cases, Flask-CDN provides a simple function, `init_app`, which takes your application as an argument.\r\n\r\n```python\r\nfrom flask import Flask\r\nfrom flask.ext.cdn import CDN\r\n\r\ncdn = CDN()\r\n\r\ndef start_app():\r\n app = Flask(__name__)\r\n cdn.init_app(app)\r\n return app\r\n```\r\n\r\nIn terms of getting your application to use external CDN URLs when referring to your application’s static assets, passing your Flask object to the CDN object is all that needs to be done. Once your app is running, any templates that contained relative static asset locations, will instead be pulled from your CDN.\r\n\r\n## Static Asset URLs\r\nURLs generated by Flask-CDN will look like the following:\r\n\r\n`/static/foo/style.css` becomes `https://mycdnname.cloudfront.net/static/foo/style.css`, assuming that mycdnname.cloudfront.net is the domain of your CDN, and you have chosen to have assets served over HTTPS.\r\n\r\n# Flask-CDN Options\r\nWithin your Flask application’s settings you can provide the following settings to control the behaviour of Flask-CDN. None of the settings are required.\r\n\r\n| Option | Description | Default |\r\n| ------ | ----------- | ------- |\r\n| `CDN_DEBUG` | Activate Debug mode to return relative url rather than CDN enabled ones. | `app.debug` |\r\n| `CDN_DOMAIN` | Set the base domain for your CDN here. | `None` |\r\n| `CDN_HTTPS` | Specifies whether or not to serve your assets over HTTPS. If not specified the asset will be served by the same method the request comes in as. | `None` |\r\n| `CDN_TIMESTAMP` | Specifies whether or not to add a timestamp to the generated urls. | `True` |\r\n| `CDN_ENDPOINTS` | The list of endpoints that will be rewritten to use the CDN. Endpoints will be checked for an exact match and also if it ends with a period followed by the endpoint name. | `['static']` |\r\n\r\n## Serve Static Assets with CloudFront\r\nCloudFront is a very simple way to seamlessly serve your static assets with it’s CDN. When a request comes into CloudFront, if the asset is not on the CDN or has expired, then CloudFront can get the asset from an “origin server”. This type of setup is called an origin pull CDN.\r\n\r\nTo setup a new CloudFront “Distribution”:\r\n\r\n- Signup for an [AWS Account](https://aws.amazon.com/)\r\n- Open the [Cloudfront Management Console](https://console.aws.amazon.com/cloudfront/)\r\n- Select Create Distribution\r\n- Leave Download selected as the delivery method and select Continue\r\n- In the Origin Domain Name field enter the domain name for your application\r\n- Change **Forward Query Strings** to **Yes**\r\n- Keep the other default values as-is and select Create Distribution\r\n\r\nIt will now take a few minutes for AWS to create the CloudFront distribution.\r\n\r\n- Set `CDN_DOMAIN` in your Flask app to the newly created ‘Domain Name’ of your Cloudfront CDN.\r\n\r\nThen you are done! Next time someone visits your site Cloudfront will cache and serve everything under the /static/ directory.\r\n",
"note": "Don't delete this file! It's used internally to help with page regeneration."
}