gws.base.web.site

Web site.

Source code: gws.base.web.site

Module Contents

class gws.base.web.site.Config(*args, **kwargs)

Bases: gws.Config

Web site the server responds to.

assets: WebDirConfig | None

Directory for assets.

canonicalHost: str = ''

Host name for canonical URLs.

contentSecurityPolicy: str = "default-src 'self'; img-src * data: blob:"

Content security policy for the site.

cors: CorsConfig | None

CORS configuration.

errorPage: gws.ext.config.template | None

Template for HTTP error pages. (deprecated in 8.4)

host: str = ''

Host name. (deprecated in 8.4)

hostnames: list[str] | None

Host names this site responds to, lowercase and without a port.

permissionsPolicy: str = 'geolocation=(self), camera=(), microphone=()'

Permissions policy for the site.

proxyCount: int = 0

Number of proxies in front of the server.

rewrite: list[RewriteRuleConfig] | None

Rewrite rules. (deprecated in 8.4)

rewriteRules: list[RewriteRuleConfig] | None

Rules to rewrite incoming URLs and URLs generated by the server.

root: WebDirConfig | None

Directory for static documents.

withDefaultRewriteRules: bool = True

Add the default rewrite rules for the application.

xFrameOptions: str = 'SAMEORIGIN'

Whether the site may be embedded in frames.

class gws.base.web.site.CorsConfig(*args, **kwargs)

Bases: gws.Config

CORS headers added to responses, to allow cross-origin requests.

allowCredentials: bool = False

Allow credentials in cross-origin requests.

allowHeaders: str = ''

Headers allowed in cross-origin requests.

allowMethods: str = ''

Methods allowed in cross-origin requests.

allowOrigin: str = ''

Origins allowed to make cross-origin requests.

maxAge: int = 5

How long the browser caches the CORS preflight response.

gws.base.web.site.DEFAULT_ASSETS_DIR = '/data/assets'
gws.base.web.site.DEFAULT_REWRITE_RULES
gws.base.web.site.DEFAULT_WEB_DIR = '/data/web'
class gws.base.web.site.Object

Bases: gws.WebSite

Web site.

contentSecurityPolicy: str

Content-Security-Policy header value.

permissionsPolicy: str

Permissions-Policy header value.

ssl: bool

The site is served over https.

xFrameOptions: str

X-Frame-Options header value.

configure()

Configuration hook.

Called when the node is initialized. Raising an exception here aborts the creation of the node.

url_for(req, path, mode, **params)

Create a URL for a request path, applying the reversed rewrite rules.

If the path, or the rewritten path, is an absolute URL, only the parameters are added. In the absolute and canonical modes, the URL gets the scheme of the request. The host is the canonical host in the canonical mode, and the request host and port otherwise or if there is no canonical host.

Parameters:
  • req – Web requester.

  • path – Request path.

  • mode – absolute, relative or canonical.

  • **params – Extra GET parameters.

Returns:

A URL.

Raises:

gws.BadRequestError – If an absolute URL is requested and there is no host.

class gws.base.web.site.RewriteRuleConfig(*args, **kwargs)

Bases: gws.Config

URL rewrite rule.

options: dict | None

Additional options.

pattern: gws.Regex

Regular expression to match the URL path against.

reversed: bool = False

Rewrite URLs generated by the server instead of incoming URLs.

target: str

Target URL.

class gws.base.web.site.SSLConfig(*args, **kwargs)

Bases: gws.Config

SSL certificate and HSTS settings.

crt: gws.FilePath

Certificate bundle location.

hsts: gws.Duration = '365d'

Max. age for the Strict-Transport-Security header.

key: gws.FilePath

Private key file location.

class gws.base.web.site.WebDirConfig(*args, **kwargs)

Bases: gws.Config

Directory served over the web.

allowMime: list[str] | None

Serve only files of these MIME types.

denyMime: list[str] | None

MIME types not to serve.

dir: gws.DirPath

Directory path.