basePath property

String get basePath

The base path under which all patterns are under.

Paths and patterns in this framework are always considered to be relative to this base path. All paths and patterns used internally must start with "~/". This is a visual reminder it is relative to the base path; and the APIs will reject paths and patterns without it.

The main purpose of these relative paths, is to ensure all paths are processed through the Request.rewriteUrl method before presenting it to the client. This mechanism ensure that all URLs get rewritten, so the sessions are preserved (if cookies are not being used to preserve sessions).

Another benefit is to change the URLs for all the pages in the server by simply changing the base path.

For example, if the base path is "/site/version/1", then the page "~/index.html" might be mapped to http:example.com:1024/site/version/1/index.html.

The default value is "/".

Implementation

String get basePath => _basePath;
set basePath (String value)

Sets the base path.

The base path is prepended to all patterns and is a simple way to "move" all the URLs to a different root.

The value must be a string that starts with a "/". Unless it is not "/", it must not end with a "/". For example, "/", "/abc", "/abc/def" are valid values. But "/abc/" and "/abc/def/" are not.

If the value is null or an empty string, it is the same as setting the base path to "/".

Implementation

set basePath(String value) {
  if (value.isEmpty) {
    _basePath = '/';
  } else if (value.startsWith('/')) {
    if (value == '/' || !value.endsWith('/')) {
      _basePath = value;
    } else {
      throw ArgumentError.value(value, 'value',
          'basePath: cannot end with "/" (unless it is just "/")');
    }
  } else {
    throw ArgumentError.value(value, 'value',
        'basePath: does not start with a "/" and is not null/blank');
  }

  _logServer.config('basePath = $_basePath');
}