@@ -59,7 +59,7 @@ Socket.IO servers to integrate easily into existing WSGI or ASGI applications::
59
59
Serving Static Files
60
60
--------------------
61
61
62
- This package offers the option to configure the serving of static files. This
62
+ The Engine.IO server can be configured to serve static files to clients . This
63
63
is particularly useful to deliver HTML, CSS and JavaScript files to clients
64
64
when this package is used without a companion web framework.
65
65
@@ -91,20 +91,38 @@ If desired, an explicit content type for a static file can be given as follows::
91
91
'/': {'filename': 'latency.html', 'content_type': 'text/plain'},
92
92
}
93
93
94
- Finally, it is also possible to configure an entire directory in a single rule,
95
- so that all the files in it are served as static files::
94
+ It is also possible to configure an entire directory in a single rule, so that all
95
+ the files in it are served as static files::
96
96
97
97
static_files = {
98
98
'/static': './public',
99
- '/': './public/index.html',
100
99
}
101
100
102
101
In this example any files with URLs starting with ``/static `` will be served
103
102
directly from the ``public `` folder in the current directory, so for example,
104
103
the URL ``/static/index.html `` will return local file ``./public/index.html ``
105
104
and the URL ``/static/css/styles.css `` will return local file
106
- ``./public/css/styles.css ``. The second rule creates a default mapping for the
107
- ``index.html `` file when the root URL is requested.
105
+ ``./public/css/styles.css ``.
106
+
107
+ If a URL that ends in a ``/ `` is requested, then a default filename of
108
+ ``index.html `` is appended to it. In the previous example, a request for the
109
+ ``/static/ `` URL would return local file ``./public/index.html ``. The default
110
+ filename to serve for slash-ending URLs can be set in the static files
111
+ dictionary with an empty key::
112
+
113
+ static_files = {
114
+ '/static': './public',
115
+ '': 'image.gif',
116
+ }
117
+
118
+ With this configuration, a request for ``/static/ `` would return
119
+ local file ``./public/image.gif ``. A non-standard content type can also be
120
+ specified if needed::
121
+
122
+ static_files = {
123
+ '/static': './public',
124
+ '': {'filename': 'image.gif', 'content_type': 'text/plain'},
125
+ }
108
126
109
127
The static file configuration dictionary is given as the ``static_files ``
110
128
argument to the ``socketio.WSGIApp `` or ``socketio.ASGIApp `` classes::
0 commit comments