gws.base.web.site

Source code: gws.base.web.site

Module Contents

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

Site (virtual host) configuration

assets: WebDirConfig | None

Root directory for assets.

canonicalHost: str = ''

Hostname for reversed URL rewriting.

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

Content Security Policy for this site.

cors: CorsConfig | None

Cors configuration.

errorPage: gws.ext.config.template | None

Error page template. (deprecated in 8.4)

host: str = ''

Host name this site responds to. (deprecated in 8.4)

hostnames: list[str] | None

Host names this site responds to, lowercase and without a port. (added in 8.4)

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

Permissions Policy for this site.

proxyCount: int = 0

Number of proxies between the client and the server which append to X-Forwarded-For. Only set this if the server is not reachable except via these proxies. (added in 8.4)

rewrite: list[RewriteRuleConfig] | None

Rewrite rules. (deprecated in 8.4)

rewriteRules: list[RewriteRuleConfig] | None

Rewrite rules. (added in 8.4)

root: WebDirConfig | None

Root directory for static documents.

withDefaultRewriteRules: bool = True

Whether to add default rewrite rules. (added in 8.4)

xFrameOptions: str = 'SAMEORIGIN'

X-Frame-Options header value. (added in 8.4)

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

CORS configuration.

allowCredentials: bool = False

Access-Control-Allow-Credentials header.

allowHeaders: str = ''

Access-Control-Allow-Headers header.

allowMethods: str = ''

Access-Control-Allow-Methods header.

allowOrigin: str = ''

Access-Control-Allow-Origin header.

maxAge: int = 5

Access-Control-Max-Age header.

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

Web site.

contentSecurityPolicy: str
permissionsPolicy: str
ssl: bool

The site is served over https.

xFrameOptions: str
configure()

Configuration hook.

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

Rewrite a request path to an Url.

Parameters:
  • req – Web Requester.

  • path – Raw request path.

  • modeabsolute, relative or canonical.

  • **params – Extra GET params.

Returns:

A rewritten URL.

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

Rewrite rule configuration.

options: dict | None

Additional options.

pattern: gws.Regex

Expression to match the url against.

reversed: bool = False

Reversed rewrite rule.

target: str

Target url with placeholders.

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

SSL configuration.

crt: gws.FilePath

Crt bundle location.

hsts: gws.Duration = '365d'

HSTS max age.

key: gws.FilePath

Key file location.

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

Web-accessible directory.

allowMime: list[str] | None

Allowed mime types.

denyMime: list[str] | None

Disallowed mime types (from the standard list).

dir: gws.DirPath

Directory path.