-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
58ba602
commit 50a3314
Showing
4 changed files
with
63 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
# Static and uploaded files | ||
|
||
The `StaticFilesMiddleware` and `UploadedFilesMiddleware` provide a way of serving | ||
static content and user uploaded files. | ||
|
||
There are two separate middlewares to allow distinct handling in the middleware | ||
pipeline. For example, you could set the uploaded files to be served after authorization, | ||
while the static files remain publicly accessible. | ||
|
||
## Usage | ||
|
||
First you need to activate the middlewares in the `settings.yaml` | ||
|
||
```yaml | ||
middleware: | ||
# ... | ||
- selva.web.middleware.files.StaticFilesMiddleware | ||
- selva.web.middleware.files.UploadedFilesMiddleware | ||
# ... | ||
``` | ||
|
||
After that, files located in the directories `resources/static` and `resources/uploads` | ||
will be served at `/static/` and `/uploads/`, respectively. | ||
|
||
## Static files mappings | ||
|
||
You can map specific paths to single static files in order to, for example, serve | ||
the favicon at `/favicon.ico` pointing to a file in `resources/static/`: | ||
|
||
```yaml | ||
middleware: | ||
- selva.web.middleware.files.StaticFilesMiddleware | ||
staticfiles: | ||
mappings: | ||
favicon.ico: my-icon.ico | ||
``` | ||
## Configuration options | ||
The available options to configure the `StaticFilesMiddleware` and `UploadedFilesMiddleware` | ||
are shown below: | ||
|
||
```yaml | ||
staticfiles: | ||
path: /static # (1) | ||
root: resources/static # (2) | ||
mappings: {} | ||
uploadedfiles: | ||
path: /uploads # (3) | ||
root: resources/uploads # (4) | ||
``` | ||
|
||
1. Path where static files are served | ||
2. Directory where static files are located | ||
3. Path where uploaded files are served | ||
4. Directory where uploaded files are located |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters