Skip to main content

Website

The cloud.Website resource represents a static website that can be hosted in the cloud. Websites are typically used to serve static content, such as HTML, CSS, and JavaScript files, which are updated whenever the application is redeployed.

Usage

Website

bring cloud;

let website = new cloud.Website(path: "./public");

Under ./public/index.html

<!DOCTYPE html>
<html>
Hello Winglang!!!
</html>

Webapp

An extended Web App example including static Website, API Gateway and a Redis database, can be found in this example project.

Target-specific details

Review the Website RFC for detailed information.

Simulator (sim)

sim implementations of cloud.Website is using nodejs express.

AWS (tf-aws and awscdk)

AWS implementations of cloud.Website uses Amazon S3 & Amazon CloudFront.

Azure (tf-azure)

🚧 Not supported yet (tracking issue: #1295)

GCP (tf-gcp)

🚧 Not supported yet (tracking issue: #1296)

API Reference

Website

A cloud static website.

Initializers

bring cloud;

new cloud.Website(props: WebsiteProps);
NameTypeDescription
propsWebsitePropsNo description.

propsRequired

Methods

Preflight Methods
NameDescription
addFileAdd a file to the website during deployment.
addJsonAdd a JSON file with custom values during the website's deployment.

addFile
addFile(path: str, data: str, options?: AddFileOptions): str

Add a file to the website during deployment.

If the path conflicts with file path from the website's static assets, an error will be thrown.

pathRequired
  • Type: str

the file path it will be uploaded as.


dataRequired
  • Type: str

the data to write to the file.


optionsOptional

configure the file's options.


addJson
addJson(path: str, data: Json): str

Add a JSON file with custom values during the website's deployment.

If the path conflicts with file path from the website's static assets, an error will be thrown.

pathRequired
  • Type: str

the file path it will be uploaded as.


dataRequired

the data to write to the file.


Static Functions

NameDescription
onLiftTypeA hook called by the Wing compiler once for each inflight host that needs to use this type inflight.

onLiftType
bring cloud;

cloud.Website.onLiftType(host: IInflightHost, ops: MutArray<str>);

A hook called by the Wing compiler once for each inflight host that needs to use this type inflight.

The list of requested inflight methods needed by the inflight host are given by ops.

This method is commonly used for adding permissions, environment variables, or other capabilities to the inflight host.

hostRequired

opsRequired
  • Type: MutArray<str>

Properties

NameTypeDescription
nodeconstructs.NodeThe tree node.
pathstrAbsolute local path to the website's static files.
urlstrThe website's url.

nodeRequired
node: Node;
  • Type: constructs.Node

The tree node.


pathRequired
path: str;
  • Type: str

Absolute local path to the website's static files.


urlRequired
url: str;
  • Type: str

The website's url.


Structs

AddFileOptions

Options for adding a file with custom value during the website's deployment.

Initializer

bring cloud;

let AddFileOptions = cloud.AddFileOptions{ ... };

Properties

NameTypeDescription
contentTypestrFile's content type.

contentTypeOptional
contentType: str;
  • Type: str

File's content type.


WebsiteDomainOptions

Options for Website.

Initializer

bring cloud;

let WebsiteDomainOptions = cloud.WebsiteDomainOptions{ ... };

Properties

NameTypeDescription
domainDomainThe website's custom domain object.

domainOptional
domain: Domain;
  • Type: Domain
  • Default: undefined

The website's custom domain object.


WebsiteOptions

Basic options for Website.

Initializer

bring cloud;

let WebsiteOptions = cloud.WebsiteOptions{ ... };

Properties

NameTypeDescription
pathstrLocal path to the website's static files, relative to the Wing source file or absolute.
errorDocumentstrName of the error document for the website.

pathRequired
path: str;
  • Type: str

Local path to the website's static files, relative to the Wing source file or absolute.


Example

"./dist"
errorDocumentOptional
errorDocument: str;
  • Type: str
  • Default: undefined

Name of the error document for the website.


Example

"404.html"

WebsiteProps

Options for Website.

Initializer

bring cloud;

let WebsiteProps = cloud.WebsiteProps{ ... };

Properties

NameTypeDescription
pathstrLocal path to the website's static files, relative to the Wing source file or absolute.
errorDocumentstrName of the error document for the website.
domainDomainThe website's custom domain object.

pathRequired
path: str;
  • Type: str

Local path to the website's static files, relative to the Wing source file or absolute.


Example

"./dist"
errorDocumentOptional
errorDocument: str;
  • Type: str
  • Default: undefined

Name of the error document for the website.


Example

"404.html"
domainOptional
domain: Domain;
  • Type: Domain
  • Default: undefined

The website's custom domain object.


Protocols

IWebsite

Base interface for a website.

Properties

NameTypeDescription
urlstrThe website URL.

urlRequired
url: str;
  • Type: str

The website URL.