Skip to content

Commit

Permalink
docs: Leave note about deploying under reverse proxy with HTTPS
Browse files Browse the repository at this point in the history
As well as include OG & Twitter Card meta tags.
  • Loading branch information
playpauseandstop committed May 17, 2020
1 parent a08421c commit 38cf321
Show file tree
Hide file tree
Showing 7 changed files with 85 additions and 10 deletions.
29 changes: 28 additions & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ aiohttp-tus
:target: https://github.com/pre-commit/pre-commit
:alt: pre-commit

.. image:: https://img.shields.io/badge/code%20style-black-000000.svg
:target: https://github.com/psf/black
:alt: black

.. image:: https://img.shields.io/pypi/v/aiohttp-tus.svg
:target: https://pypi.org/project/aiohttp-tus/
:alt: Latest Version
Expand Down Expand Up @@ -67,7 +71,30 @@ Chunk Size
Please, make sure to configure ``client_max_size`` for ``aiohttp.web`` Application and
supply proper ``chunkSize`` for Uppy.io or other tus.io client.

`Documentation <https://aiohttp-tus.readthedocs.io/en/latest/usage.html#understanding-tus-io-chunk-size>`_
`Documentation <https://aiohttp-tus.readthedocs.io/en/latest/usage.html#understanding-tus-io-chunk-size>`__

CORS Headers
============

To setup CORS headers you need to use `cors_middleware <https://aiohttp-middlewares.readthedocs.io/en/latest/usage.html#cors-middleware>`_
from `aiohttp-middlewares`_ package. `aiohttp-cors <https://pypi.org/project/aiohttp-cors/>`_
library not supported cause of
`aio-libs/aiohttp-cors#241 <https://github.com/aio-libs/aiohttp-cors/issues/241>`_
issue.

`Documentation <https://aiohttp-tus.readthedocs.io/en/latest/usage.html#cors-headers>`__

.. _aiohttp-middlewares: https://pypi.org/project/aiohttp-middlewares/

Reverse proxy and HTTPS
=======================

When ``aiohttp`` application deployed under the reverse proxy (such as nginx) with HTTPS
support, it is needed to use `https_middleware <https://aiohttp-middlewares.readthedocs.io/en/latest/usage.html#https-middleware>`_
from `aiohttp-middlewares`_ package to ensure that ``web.Request`` instance has proper
schema.

`Documentation <https://aiohttp-tus.readthedocs.io/en/latest/usage.html#reverse-proxy-and-https>`__

Examples
========
Expand Down
2 changes: 2 additions & 0 deletions docs/api.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
.. include:: meta.rst

=============
API Reference
=============
Expand Down
1 change: 1 addition & 0 deletions docs/authors.rst
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
.. include:: meta.rst
.. include:: ../AUTHORS.rst
1 change: 1 addition & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
.. include:: meta.rst
.. include:: ../CHANGELOG.rst
1 change: 1 addition & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.. include:: meta.rst
.. include:: ../README.rst

Installation
Expand Down
13 changes: 13 additions & 0 deletions docs/meta.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
.. meta::
:description: Documentation of tus.io server implementation for aiohttp.web applications.
:og:title: aiohttp-tus
:og:description: Documentation of tus.io server implementation for aiohttp.web applications.
:og:type: website
:og:image: https://repository-images.githubusercontent.com/245408929/c407b000-695b-11ea-802d-c72f699ce95a
:og:image:width: 1280
:og:image:height: 640
:og:image:alt: aiohttp-tus
:twitter:card: summary_large_image
:twitter:image:src: https://repository-images.githubusercontent.com/245408929/c407b000-695b-11ea-802d-c72f699ce95a
:twitter:title: aiohttp-tus
:twitter:description: Documentation of tus.io server implementation for aiohttp.web applications.
48 changes: 39 additions & 9 deletions docs/usage.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
.. include:: meta.rst

=====
Usage
=====
Expand Down Expand Up @@ -78,9 +80,11 @@ uppy.io Configuration
CORS Headers
============

At a moment (`Mar 26 2020`), ``aiohttp-tus`` supports setting up CORS Headers for
``aiohttp.web`` application only via `cors_middleware <https://https://aiohttp-middlewares.readthedocs.io/en/latest/usage.html#cors-middleware>`_
from ``aiohttp-middlewares`` package.
At a moment (`May 17 2020`), ``aiohttp-tus`` supports setting up CORS Headers for
``aiohttp.web`` application only via `cors_middleware <https://aiohttp-middlewares.readthedocs.io/en/latest/usage.html#cors-middleware>`_
from `aiohttp-middlewares`_ package.

.. _aiohttp-middlewares: https://aiohttp-middlewares.readthedocs.io/

As ``aiohttp-tus`` registers `OPTIONS` handlers it doesn't work with
`aiohttp-cors <https://github.com/aio-libs/aiohttp-cors>`_ library cause of known issue
Expand All @@ -90,7 +94,7 @@ As ``aiohttp-tus`` registers `OPTIONS` handlers it doesn't work with
To enable CORS Headers for your ``aiohttp.web`` application, which is using
``aiohttp-tus``, you need to,

1. Install `aiohttp-middlewares <https://aiohttp-middlewares.readthedocs.io>`_
1. Install `aiohttp-middlewares`_
2. In your `app.py`,

.. code-block:: python
Expand All @@ -104,13 +108,39 @@ To enable CORS Headers for your ``aiohttp.web`` application, which is using
# Allow CORS Headers for requests from http://localhost:3000
app = web.Application(
middlewares=[
cors_middleware(origins=["http://localhost:3000"])
]
middlewares=(
cors_middleware(origins=("http://localhost:3000",)),
)
)
setup_tus(
app,
upload_path=Pathlib(__file__).parent.parent / "uploads",
app, upload_path=Path(__file__).parent.parent / "uploads",
)
Reverse proxy and HTTPS
=======================

When aiohttp web application with ``aiohttp-tus`` deployed under the reverse proxy
(such as nginx), with HTTPS support **you need to** setup
`https_middleware <https://aiohttp-middlewares.readthedocs.io/en/latest/usage.html#https-middleware>`_
from `aiohttp-middlewares`_ package to ensure that :class:`aiohttp.web.Request`
instance has proper schema.

To use HTTPS middleware you need to,

1. Install `aiohttp-middlewares`_
2. In `app.py`,

.. code-block:: python
from pathlib import Path
from aiohttp import web
from aiohttp_middlewares import https_middleware
from aiohttp_tus import setup_tus
app = web.Application(middlewares=(https_middleware(),))
setup_tus(
app, upload_path=Path(__file__).parent.parent / "uploads"
)
User Uploads
Expand Down

0 comments on commit 38cf321

Please sign in to comment.