Houdini 19.0 hwebserver

hwebserver.registerStaticFilesDirectory function

Tells Houdini’s web server to check the given directory for files to automatically serve for URLs that match the given path prefix.

registerStaticFilesDirectory(directory, url_prefix="/static", port=-1)

When the server receives a request whose path starts with url_prefix, if the remaining part of the request path, appended to the directory path, is a file that exists, the server will automatically serve that file to the client. The port can be optionally specified if this handler should not run on the main port the server is running on.

Call this function before you call hwebserver.run, not from a URL handler.

For example, if you do this:

hwebserver.registerStaticFilesDirectory("/var/www/files", "/static")

…and the client requests this server path:

/static/css/main.css

…and this file exists:

/var/www/files/css/main.css

…then the server will automatically serve the main.css file to the client without involving a Python handler.

You should try to set up the server so it serves any static files (files that are not generated dynamically from Houdini data, for example CSS and JavaScript files) this way, rather than in a Python handler.

Note

If a URL handler has a URL is more specific (matches more path parts) than the static path prefix, the server will use the handler instead of static lookup.

For example, even if you registered the static directory above, if the client requested /static/geo/foo.bgeo and you have a dynamic handler for /static/geo, the server would use the handler instead of looking for a static file.

This might be useful if you need a few dynamically generated resources mixed in with otherwise static files in the server namespace. However, it’s usually best to avoid the confusion and keep static resources separate from dynamic resources, such as by using the default /static prefix for static files.

See also

hwebserver

クラス

開始と停止

ウェブリクエストの処理とレスポンスの返し

ウェブソケット

  • WebSocket

    Base class for WebSocket support with the embedded server.

  • hwebserver.webSocket

    Decorator for registering WebSocket classes with Houdini’s web server.

APIコール

  • hwebserver.apiFunction

    Decorator for functions that can be called through an API endpoint on Houdini’s web server, returning JSON or binary responses.

  • hwebserver.APIError

    Raise this exception in apiFunction handlers to indicate an error.